Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename initFromKey to instanceFromKey
  • Loading branch information
jodiedunlop committed Sep 13, 2018
commit ffdaea3c1f2bcc0f793389e2a21f22c7946d479a
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 1.2.0
# [Unreleased]

- Add Enum::initFromKey($key)
- Add Enum::instanceFromKey($key)

# 1.1.0

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ Animal::DOG()->value(); // (null) - No value was assigned in map()
Animal::PIGEON()->key(); // "skyrat"
Animal::PIGEON()->value(); // (array)['you', 'filthy', 'animal']

// Init from key in variable
// Get a new Enum instance from a given key
$kitty = 'kitty';
$cat = Animal::initFromKey($kitty);
$cat = Animal::instanceFromKey($kitty);
```

## Dependencies
Expand Down Expand Up @@ -211,9 +211,9 @@ Returns the value (or null if not mapped) for the given key (as declared in the
Returns the constant for the given value (as declared in the `map()` method).
> Caveats: Only works with single dimension arrays and it will only return the last key if multiple keys have the same value.

### initFromKey($key)
### instanceFromKey($key)

Create instance of this Enum from the key.
Create instance of this Enum from the given key.

### exists(string $key)

Expand Down
2 changes: 1 addition & 1 deletion src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static function fromValue($value)
* @return static
* @throws InvalidKeyException
*/
public static function initFromKey($key): self
public static function instanceFromKey($key): self
{
foreach (self::constantMap() as $identifier => $validKey) {
if ($key === $validKey) {
Expand Down