Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
da26127
Change identifier to name
jodiedunlop Sep 14, 2018
6745120
Change static method valueFor() to valueForKey()
jodiedunlop Sep 14, 2018
df27a89
Add static method nameForKey()
jodiedunlop Sep 14, 2018
6400bb8
Change exists() and checkExists() to isValidKey() and requireValidKey…
jodiedunlop Sep 14, 2018
ce9166e
Improve keyForName()
jodiedunlop Sep 14, 2018
078f0a7
Fix error in key() when the key is not a string (eg. int)
jodiedunlop Sep 14, 2018
1f024a9
Fix is() instance method to handle non-string keys
jodiedunlop Sep 14, 2018
ad4f245
Fix late-static binding: change self references
jodiedunlop Sep 18, 2018
d159b97
Add Enum::instanceFromName() method
jodiedunlop Sep 19, 2018
10162b7
Change implementation of instanceFromKey() to use array_search
jodiedunlop Sep 19, 2018
c865499
Rename some internal variables
jodiedunlop Sep 19, 2018
434d78b
Removed flip() and renamed fromValue() to keyForValue()
jodiedunlop Sep 19, 2018
b1e9572
Change nameForKey implementation and throw on duplicate keys
jodiedunlop Sep 19, 2018
257ab25
Add uncommitted duplicate key classes
jodiedunlop Sep 19, 2018
549f8d3
Rename Enum::constantMap() method to namesAndKeys()
jodiedunlop Sep 21, 2018
f1e6c52
Update README to document API changes
jodiedunlop Sep 21, 2018
2031ec1
Add Enum::valueForName() method
jodiedunlop Sep 23, 2018
c616f17
Rename Bevs stub to Beverages
jodiedunlop Sep 23, 2018
903e409
Fix isValidName() to handle null keys
jodiedunlop Sep 23, 2018
32e71ee
Update CHANGELOG for 2.0.0 release
jodiedunlop Sep 23, 2018
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
Improve keyForName()
  • Loading branch information
jodiedunlop committed Sep 14, 2018
commit ce9166e53ea7d39a01d62c669efa817b6b796d1a
7 changes: 2 additions & 5 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,15 @@ public static function __callStatic($name, $arguments)
}

/**
* Get the key for the given constant name
* Get the key for the given constant name.
*
* @param string $name
*
* @return null|mixed|string
*/
public static function keyForName(string $name)
{
$key = null;
$map = static::constantMap();

return $map[$name] ?? null;
return static::constantMap()[$name] ?? null;
}

/**
Expand Down