-
-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show enum case name in output #874
Conversation
👀 I didn't get the chance to look at this, but it seems like a good idea. Still interested? |
If you can't reopen it, I would gladly redo it |
@@ -90,7 +90,7 @@ enum_exists($enum) && method_exists($enum, 'tryFrom') | |||
// $case->value only exists on BackedEnums, not UnitEnums | |||
// method_exists($enum, 'tryFrom') implies $enum instanceof BackedEnum | |||
// @phpstan-ignore-next-line | |||
$rulesList[] = 'in:' . implode(',', array_map(fn ($case) => $case->value, $enum::cases())); | |||
$rulesList[] = 'in:' . implode(',', array_map(fn ($case) => "$case->value ($case->name)", $enum::cases())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete this line because it's not needed. The rulesList is the actual list of rules that Laravel supports, and changing this from in:1,2,3
to in:1 (MALE),2 (FEMALE),3 (UNDEFINED)
will probably break things.
$cases = []; | ||
foreach ($type::cases() as $case) { | ||
/** @var BackedEnum $case */ | ||
$cases[$case->name] = $case->value; | ||
} | ||
|
||
$parameterData['type'] = gettype(reset($cases)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, what does this do? The $cases
array is not used for anything else beyond getting the type, and it does the same thing as the previous version, which works for Backed Enums.
I can't reopen it, as the repository has been deleted. 😞 Please redo if you can (but see my comments). |
In cases where BackedEnums have int type, the output is just a list of numbers, ex:
With this changes, enums with int type will show the base name of the case: