enum
enum copied to clipboard
PHP 8.1
@brendt could you please check these changes. I don't want to fully abandon the package - primary because of the faker provider and phpunit assertions.
There are some interfaces missing and the code isn't perfect. But these three traits are what I can reduce to.
The value()
method is only for convenience so you don't have to use $enum->value
but $enum->label()
.
Do you have some more things in mind we could/should keep?
Looking good, only two minor remarks. I think these traits offer enough value to keep the package alive for now :)
@brendt as you can't type-hint traits - what do you think about an interface? This would make type-safety for the Laravel wrapper easier and allows other packages/apps to interact with this base package.
What would you call the interface?
Enum, Enumerable, EnumContract - I'm open for everything. But I would add only one combining all traits of the package. So that we can build on all of them without checking for multiple interfaces and telling the user which features requires what interface.
Then you'd only be able to implement the interface if you use all traits. I'm fine with that simplicity, but why not combine all traits into one as well then?
Would also be fine with combining the traits.
Is there a guide somewhere for migrating from Spatie enums to native PHP enums?
https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#spatieenumclasstoenumrector
Besides that you will have to replace all "method" calls with constant-like calls.
For MyClabs there's a rule, you can probably adjust it or even add it to rector. https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#myclabsmethodcalltoenumconstrector
Last one will be replacing all ->equals()
calls with ===
or in_array()
or add the ->equals()
method via trait or whatever to your enums as it can be really useful.
Closing due to inactivity.