Fix MODEL-ENUMS-01 to properly detect top-level keys and ignore comments

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-26 03:36:41 +00:00
parent 051ab489d0
commit aac7585b8c

View File

@@ -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,9 +137,8 @@ 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 === '"') {
// 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;
@@ -161,9 +156,16 @@ class ModelEnums_CodeQualityRule extends CodeQualityRule_Abstract
$top_level_fields[] = $key;
}
}
$i = $j; // Skip past the 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++;