$match) { $full_match = $match[0]; $offset = $match[1]; $controller = $matches[1][$index][0]; // Calculate line number $line_number = substr_count(substr($contents, 0, $offset), "\n") + 1; // Extract the line for snippet $lines = explode("\n", $contents); $code_snippet = isset($lines[$line_number - 1]) ? trim($lines[$line_number - 1]) : $full_match; // Build remediation message $is_php = str_ends_with($file_path, '.php') || str_ends_with($file_path, '.blade.php'); $operator = $is_php ? '::' : '.'; $correct_usage = "Rsx{$operator}Route('{$controller}')"; $remediation = "The 'index' action is the default value and should be omitted.\n\n"; $remediation .= "CURRENT (redundant):\n"; $remediation .= " {$full_match}\n\n"; $remediation .= "CORRECTED (cleaner):\n"; $remediation .= " {$correct_usage}\n\n"; $remediation .= "CONVENTION:\n"; $remediation .= "The second parameter of Rsx{$operator}Route() defaults to 'index'.\n"; $remediation .= "Only specify the action when it's NOT 'index'.\n\n"; $remediation .= "EXAMPLES:\n"; $remediation .= " Rsx{$operator}Route('User_Controller') // Goes to index action\n"; $remediation .= " Rsx{$operator}Route('User_Controller', 'edit') // Goes to edit action\n"; $remediation .= " Rsx{$operator}Route('User_Controller', 'show') // Goes to show action"; $this->add_violation( $file_path, $line_number, "Redundant 'index' action in Route call", $code_snippet, $remediation, 'low' ); } } } }