marc-mabe / php-enum

Simple and fast implementation of enumerations with native PHP
BSD 3-Clause "New" or "Revised" License
464 stars 36 forks source link

add has-method #53

Closed prolic closed 9 years ago

marc-mabe commented 9 years ago

For isValidName: you can simply do defined("MyEnum::NAME") instead.

prolic commented 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.

prolic commented 9 years ago
$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.

prolic commented 9 years ago

Damn scrutinizer won't succeed

marc-mabe commented 9 years ago

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
prolic commented 9 years ago

changed as requested

prolic commented 9 years ago

done

marc-mabe commented 9 years ago

Please can you also address my small code comments and rebase all your commits together. Thanks!

prolic commented 9 years ago

I hope this is okay this time ;)