-
Notifications
You must be signed in to change notification settings - Fork 102
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
Complete baking of enums. #972
Conversation
IMO it should be |
Also instead of using uppercase case names I would use capitalized case names. |
Co-authored-by: othercorey <[email protected]>
Arent those kind of constants?
So I guessed that we are now using UPPER_CASE instead of CamelCase here as convention. Whatever we decide on, we probably want to have a code sniffer rule for it. |
I was more thinking of how we all know arrays work with |
src/Command/EnumCommand.php
Outdated
{ | ||
$formatted = []; | ||
foreach ($cases as $case => $alias) { | ||
$alias = mb_strtoupper(Inflector::underscore($alias)); |
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.
Do we need to underscore? Developers could input their choices as snake_case
or UPPER_CASE
. Do we also need to support mixedCase
?
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.
All cases should be possible now, as only the case is touched, not the value
I have always preferred CamelCased names but probably went with the consensus opinion :). Since the couple of core enums use upper case I guess that's what we have settled on. |
UPPERCASE enum cases usually come from other languages where convention is to use underscores to separate words in the case:
|
The current understanding is mainly that those are close to constants. Thus the uppercase. |
I'm happy to treat enums as constants if that is the convention. |
My personal preference would be to use CamelCase for enum values. But I also recognize that uppercase is more aligned with conventions for constants. Are there other projects we should be looking at to share conventions with? |
Good question But then again, it seems a bit harder to read what is the enum (class), what is the case and what is the property.. |
Enums can have constants. Can't think of a use case for them but if someone did have them then they wouldn't be able to easily distinguish between the constants and case. |
https://github.com/php-fig/per-coding-style/blob/master/spec.md#9-enumerations |
https://symfony.com/doc/current/contributing/code/standards.html |
Hmm then would recommend switching core first
|
Funny they don't try to distinguish them either. |
Co-authored-by: Mark Story <[email protected]>
I also tested in in real life with int + string + nullable each. |
Completes #968 and #969
Now fully supports baking enums including cases.
Examples
implicit cases for string:
explicit cases for string:
implicit cases for int:
explicit cases for int:
On top of that now also bake all works completely out of the box when you set a
[enum]
marker + optional case config as comment:will generate
If this sounds fine as is, I will add a few more test cases.
Just wanted to get some feedback on it first.
Also, open tasks:
->label()
.