diff --git a/app/RSpade/CodeQuality/Rules/Models/ModelEnums_CodeQualityRule.php b/app/RSpade/CodeQuality/Rules/Models/ModelEnums_CodeQualityRule.php index 85e9ed589..ea0e2c628 100644 --- a/app/RSpade/CodeQuality/Rules/Models/ModelEnums_CodeQualityRule.php +++ b/app/RSpade/CodeQuality/Rules/Models/ModelEnums_CodeQualityRule.php @@ -109,13 +109,68 @@ class ModelEnums_CodeQualityRule extends CodeQualityRule_Abstract // We need to identify the structure: // 'field_name' => [ integer_value => ['constant' => ..., 'label' => ...], ... ] - // First, find the top-level keys (any field name allowed, special handling for is_ prefix) - // We'll look for patterns like 'key' => [ or "key" => [ - $pattern = '/[\'"]([^\'"]+)[\'\"]\s*=>\s*\[/'; - if (preg_match_all($pattern, $enums_content, $field_matches, PREG_OFFSET_CAPTURE)) { - foreach ($field_matches[1] as $field_match) { - $field = $field_match[0]; - $offset = $field_match[1]; + // Extract only TOP-LEVEL keys (field definitions) by tracking bracket depth + // This prevents matching nested custom properties like 'permissions' => [...] + $top_level_fields = []; + $bracket_depth = 0; + $in_string = false; + $string_char = null; + $i = 0; + $len = strlen($enums_content); + + while ($i < $len) { + $char = $enums_content[$i]; + + // Track string boundaries + if (!$in_string && ($char === "'" || $char === '"')) { + $in_string = true; + $string_char = $char; + } elseif ($in_string && $char === $string_char && ($i === 0 || $enums_content[$i - 1] !== '\\')) { + $in_string = false; + $string_char = null; + } + + // Track bracket depth when not in string + if (!$in_string) { + if ($char === '[') { + $bracket_depth++; + } elseif ($char === ']') { + $bracket_depth--; + } + } + + // Look for field definitions at depth 1 (inside the outer $enums = [...] bracket) + // Pattern: 'field_name' => [ + if ($bracket_depth === 1 && !$in_string) { + // Check if we're at the start of a string key + if ($char === "'" || $char === '"') { + $quote = $char; + $key_start = $i + 1; + $j = $key_start; + // Find the closing quote + while ($j < $len && $enums_content[$j] !== $quote) { + $j++; + } + if ($j < $len) { + $key = substr($enums_content, $key_start, $j - $key_start); + // Check if followed by => [ + $after_key = ltrim(substr($enums_content, $j + 1, 20)); + if (str_starts_with($after_key, '=>')) { + $after_arrow = ltrim(substr($after_key, 2)); + if (str_starts_with($after_arrow, '[')) { + $top_level_fields[] = $key; + } + } + $i = $j; // Skip past the key + } + } + } + + $i++; + } + + // Now validate each top-level field + foreach ($top_level_fields as $field) { // No naming convention enforcement - any field name is allowed // Only requirement: integer keys for values (checked below) @@ -338,7 +393,6 @@ class ModelEnums_CodeQualityRule extends CodeQualityRule_Abstract } } // End of non-boolean field checks } - } } } } diff --git a/app/RSpade/CodeQuality/Rules/Models/ModelRelations_CodeQualityRule.php b/app/RSpade/CodeQuality/Rules/Models/ModelRelations_CodeQualityRule.php index d6ffcc862..a75f505ba 100644 --- a/app/RSpade/CodeQuality/Rules/Models/ModelRelations_CodeQualityRule.php +++ b/app/RSpade/CodeQuality/Rules/Models/ModelRelations_CodeQualityRule.php @@ -106,8 +106,26 @@ class ModelRelations_CodeQualityRule extends CodeQualityRule_Abstract $relationship_methods = []; $complex_relationships = []; + // Track multi-line comment state + $in_multiline_comment = false; + // Parse each method to find relationships foreach ($lines as $i => $line) { + // Track multi-line comment state + // Check for comment start (but not if it's closed on same line) + if (preg_match('#/\*#', $line) && !preg_match('#/\*.*\*/#', $line)) { + $in_multiline_comment = true; + } + // Check for comment end + if (preg_match('#\*/#', $line)) { + $in_multiline_comment = false; + continue; // Skip the closing line too + } + // Skip lines inside multi-line comments + if ($in_multiline_comment) { + continue; + } + // Look for public non-static function declarations if (preg_match('/public\s+(?!static\s+)function\s+(\w+)\s*\(/', $line, $func_match)) { $method_name = $func_match[1];