parse_with_acorn($file_path); if (empty($violations)) { return; } // Process violations foreach ($violations as $violation) { $this->add_violation( $file_path, $violation['line'], $violation['message'], $violation['codeSnippet'], $violation['remediation'], $this->get_default_severity() ); } } /** * Analyze JavaScript file for 'this' usage violations via RPC server */ private function parse_with_acorn(string $file_path): array { // Setup cache directory $cache_dir = storage_path('rsx-tmp/cache/code-quality/js-this'); if (!is_dir($cache_dir)) { mkdir($cache_dir, 0755, true); } // Cache based on file modification time $cache_key = md5($file_path) . '-' . filemtime($file_path); $cache_file = $cache_dir . '/' . $cache_key . '.json'; // Check cache first if (file_exists($cache_file)) { $cached = json_decode(file_get_contents($cache_file), true); if ($cached !== null) { return $cached; } } // Clean old cache files for this source file $pattern = $cache_dir . '/' . md5($file_path) . '-*.json'; foreach (glob($pattern) as $old_cache) { if ($old_cache !== $cache_file) { unlink($old_cache); } } // Analyze via RPC server (lazy starts if not running) $violations = Js_CodeQuality_Rpc::analyze_this($file_path); // Cache the result file_put_contents($cache_file, json_encode($violations)); return $violations; } }