From b13a9cb8a5e33d70605973da5726496db1241549 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 21 Oct 2025 06:13:23 +0000 Subject: [PATCH] Add validation for integer-only enum values in Constants_Regenerate_Command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Rsx/Constants_Regenerate_Command.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/RSpade/Commands/Rsx/Constants_Regenerate_Command.php b/app/RSpade/Commands/Rsx/Constants_Regenerate_Command.php index 82ae86b11..9769dd7d0 100755 --- a/app/RSpade/Commands/Rsx/Constants_Regenerate_Command.php +++ b/app/RSpade/Commands/Rsx/Constants_Regenerate_Command.php @@ -147,6 +147,27 @@ class Constants_Regenerate_Command extends Command $docblock .= " * @method static mixed {$column}_enum_ids()\n"; $seenProps = []; foreach ($enumValues as $value => $props) { + // Validate that enum value is an integer + if (!is_int($value) && !ctype_digit((string)$value)) { + throw new Exception( + "Invalid enum value '{$value}' for column '{$column}' in model '{$fullClassName}'.\n\n" . + "ENUM VALUES MUST BE INTEGERS.\n\n" . + "The purpose of enum values is to store an INTEGER in the database that corresponds to a " . + "string in the enum definition. The string label can then be changed in the enum 'label' " . + "property without affecting the database value, so long as it continues to correspond to " . + "the same numeric integer.\n\n" . + "Example of a properly defined enum:\n\n" . + " protected static \$enums = [\n" . + " 'status' => [\n" . + " 1 => ['label' => 'Active', 'constant' => 'STATUS_ACTIVE'],\n" . + " 2 => ['label' => 'Inactive', 'constant' => 'STATUS_INACTIVE'],\n" . + " 3 => ['label' => 'Pending', 'constant' => 'STATUS_PENDING'],\n" . + " ],\n" . + " ];\n\n" . + "For more information, run: php artisan rsx:man enums" + ); + } + foreach ($props as $p => $v) { if (!in_array($p, $seenProps)) { $docblock .= " * @property-read mixed \${$column}_{$p}\n";