patterns // Match Define tag with component name and class attribute on same line if (preg_match('/]*class=["\']([^"\']*)["\']/', $line, $matches)) { $component_name = $matches[1]; $class_attribute = $matches[2]; // Check if component name appears in the class attribute // Use word boundary to avoid false positives (e.g., "Client" in "Client_Selector") if (preg_match('/\b' . preg_quote($component_name, '/') . '\b/', $class_attribute)) { $this->add_violation( $file_path, $line_number, "Redundant class name '{$component_name}' in Define tag class attribute", trim($line), "Remove '{$component_name}' from the class attribute. Component names are automatically added to the rendered element's class list by the jqhtml framework. Explicitly including the component name in the class attribute is unnecessary.\n\n" . "CURRENT:\n" . " \n\n" . "CORRECTED:\n" . " remove_component_from_class($class_attribute, $component_name) . "\">", 'medium' ); } } } } /** * Remove component name from class attribute string * * @param string $class_attribute The class attribute value * @param string $component_name The component name to remove * @return string The cleaned class attribute */ private function remove_component_from_class(string $class_attribute, string $component_name): string { // Remove the component name, handling multiple spaces $cleaned = preg_replace('/\b' . preg_quote($component_name, '/') . '\b\s*/', '', $class_attribute); // Clean up any double spaces $cleaned = preg_replace('/\s+/', ' ', $cleaned); // Trim leading/trailing spaces return trim($cleaned); } }