$line) { foreach ($this->banned_relations as $banned) { if (preg_match('/\$this->' . preg_quote($banned) . '\s*\(/', $line)) { // Find the method name this is in $method_name = 'unknown'; for ($j = $i; $j >= 0; $j--) { if (preg_match('/function\s+(\w+)\s*\(/', $processed_lines[$j], $match)) { $method_name = $match[1]; break; } } $this->add_violation( $file_path, $i + 1, "Model uses banned relationship '{$banned}' in method '{$method_name}'", $line, 'Replace with explicit relationship traversal or simpler patterns. ' . 'For example, use $this->relation1->flatMap->relation2 or create a ' . 'method that explicitly queries the related data.', 'critical' ); } } } } }