Skip to content

Conversation

prolic
Copy link
Collaborator

@prolic prolic commented Sep 28, 2015

No description provided.

@marc-mabe
Copy link
Owner

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

@prolic
Copy link
Collaborator Author

prolic commented Sep 28, 2015

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
Copy link
Collaborator Author

prolic commented Sep 28, 2015

$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
Copy link
Collaborator Author

prolic commented Sep 28, 2015

Damn scrutinizer won't succeed

@marc-mabe
Copy link
Owner

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

@marc-mabe marc-mabe self-assigned this Sep 28, 2015
@prolic
Copy link
Collaborator Author

prolic commented Sep 28, 2015

changed as requested

$class = get_called_class();
$constants = self::detectConstants($class);
$name = array_search($value, $constants, true);
return $name !== false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return in_array($value, $constants, true);

@prolic
Copy link
Collaborator Author

prolic commented Sep 28, 2015

done

@marc-mabe
Copy link
Owner

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

@prolic prolic changed the title add isValid* methods add has-method Sep 28, 2015
@prolic
Copy link
Collaborator Author

prolic commented Sep 28, 2015

I hope this is okay this time ;)

@marc-mabe marc-mabe merged commit 5183fc8 into marc-mabe:master Oct 3, 2015
@prolic prolic deleted the isValid_2 branch October 4, 2015 11:26
@marc-mabe marc-mabe added this to the 2.2.0 milestone Oct 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants