-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/refactor api #4
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
Conversation
- Updated tests - Changed internal implementation of keyForValue
lachlankrautz
left a comment
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.
Agree with all the new names, much "clearer" which is important because it can be used in many contexts
|
|
||
| use Rexlabs\Enum\Enum; | ||
|
|
||
| class Animal extends Enum |
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.
Changing from animals to cities is anthropocentric
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.
TIL
| * @throws InvalidKeyException | ||
| */ | ||
| public static function checkExists($key) | ||
| public static function requireValidKey($key) |
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.
Much clearer
| - **Breaking** Change `$instance->identifier` to `$instance->name()` | ||
| - **Breaking** Change `Enum::identifiers()` to `Enum::names()` | ||
| - **Breaking** Change `Enum::getKeyForIdentfier()` to `Enum::keyForName()` | ||
| - **Breaking** Change `Enum::valueFor()` to `Enum::valueForKey()` |
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.
Enum::valueForName() for completeness?
Refactored API as discussed in issue #3
$instance->identifier()to$instance->name()Enum::identifiers()toEnum::names()Enum::getKeyForIdentfier()toEnum::keyForName()Enum::valueFor()toEnum::valueForKey()Enum::nameForKey()to get the constant name for a given keyEnum::exists()toEnum::isValidKey()Enum::checkExists()toEnum::requireValidKey()$instance->key()to handle non-string keys$instance->is()to handle non-string keysself::Enum::instanceFromName($name)to get an instance via name (alternative to Enum::NAME())Enum::instanceFromKey($key)to use array_searchmap()method will return an array of constant keys mapped tonull.Previously it returned an empty array
[]when not overridden. In practice, this may not effect userland code.map()method implementedin your sub-class. This method should be used to map keys to values (if necessary). A default map() method is provided
which maps keys to
nullvalues.Enum::fromValue($val)has been renamed toEnum::keyForValue()Enum::flip()