diff --git a/app/RSpade/CodeQuality/Rules/Models/ModelEnums_CodeQualityRule.php b/app/RSpade/CodeQuality/Rules/Models/ModelEnums_CodeQualityRule.php index ea0e2c628..9d73c84e6 100644 --- a/app/RSpade/CodeQuality/Rules/Models/ModelEnums_CodeQualityRule.php +++ b/app/RSpade/CodeQuality/Rules/Models/ModelEnums_CodeQualityRule.php @@ -103,6 +103,11 @@ class ModelEnums_CodeQualityRule extends CodeQualityRule_Abstract // Check structure of $enums array $enums_content = $match[1]; + // Strip inline comments from $enums_content to avoid false matches + // Removes // comments and /* */ comments + $enums_content = preg_replace('#//[^\n]*#', '', $enums_content); + $enums_content = preg_replace('#/\*.*?\*/#s', '', $enums_content); + // If not empty array, validate structure if (trim($enums_content) !== '[]') { // Parse the enums array more carefully @@ -121,15 +126,6 @@ class ModelEnums_CodeQualityRule extends CodeQualityRule_Abstract 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 === '[') { @@ -141,29 +137,35 @@ class ModelEnums_CodeQualityRule extends CodeQualityRule_Abstract // 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 - } + // Check BEFORE updating in_string so we can detect the opening quote of keys + if ($bracket_depth === 1 && !$in_string && ($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 (closing quote) + } + } + // Track string boundaries for non-key strings (values, nested content) + elseif (!$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; } $i++;