Skip to content
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

Closed
wants to merge 4 commits into from
Closed

Show enum case name in output #874

wants to merge 4 commits into from

Conversation

Lea-Reif
Copy link

In cases where BackedEnums have int type, the output is just a list of numbers, ex:
image
With this changes, enums with int type will show the base name of the case:
image

@Lea-Reif Lea-Reif closed this by deleting the head repository Aug 21, 2024
@shalvah
Copy link
Contributor

shalvah commented Aug 24, 2024

👀

I didn't get the chance to look at this, but it seems like a good idea. Still interested?

@Lea-Reif
Copy link
Author

Lea-Reif commented Sep 5, 2024

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()));
Copy link
Contributor

@shalvah shalvah Sep 15, 2024

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.

Comment on lines +212 to +218
$cases = [];
foreach ($type::cases() as $case) {
/** @var BackedEnum $case */
$cases[$case->name] = $case->value;
}

$parameterData['type'] = gettype(reset($cases));
Copy link
Contributor

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.

@shalvah
Copy link
Contributor

shalvah commented Sep 15, 2024

I can't reopen it, as the repository has been deleted. 😞 Please redo if you can (but see my comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants