Closed prolic closed 9 years ago
So should I remove isValidName? I like this method because it allows me to do this:
$enum->isValidName('FOO');
without having the enum-class at hand.
$foo = 'BAR';
MyEnum::isValid($bar)
VS
defined(MyEnum::class . '::' . $bar)
I would prefere the first version (with method), it's less code to write and more explicit, imho. But you decide @marc-mabe.
Damn scrutinizer won't succeed
I don't see a real need for isValidName()
For isValidOrdinal()
: You can simply check: $ord < count(MyEnum::getConstants())
For isValid()
it makes sense because there is no simple and fast way to check (I only don't like the name).
What about:
final public static function has($enumerator) : bool
MyEnum::has(MyEnum::ONE); // true
MyEnum::has(MyEnum::ONE()); // true
MyEnum::has(AnotherEnum::ONE()); // false
MyEnum::has('unknown'); // false
changed as requested
done
Please can you also address my small code comments and rebase all your commits together. Thanks!
I hope this is okay this time ;)
For
isValidName
: you can simply dodefined("MyEnum::NAME")
instead.