Add validation for integer-only enum values in Constants_Regenerate_Command
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user