@@ -70,7 +70,7 @@ public function getKey()
7070 */
7171 public function __toString ()
7272 {
73- return (string ) $ this ->value ;
73+ return (string )$ this ->value ;
7474 }
7575
7676 /**
@@ -108,7 +108,7 @@ public static function toArray()
108108 {
109109 $ class = get_called_class ();
110110 if (!array_key_exists ($ class , self ::$ cache )) {
111- $ reflection = new \ReflectionClass ($ class );
111+ $ reflection = new \ReflectionClass ($ class );
112112 self ::$ cache [$ class ] = $ reflection ->getConstants ();
113113 }
114114
@@ -119,6 +119,7 @@ public static function toArray()
119119 * Check if is valid enum value
120120 *
121121 * @param $value
122+ *
122123 * @return bool
123124 */
124125 public static function isValid ($ value )
@@ -136,6 +137,7 @@ public static function isValid($value)
136137 public static function isValidKey ($ key )
137138 {
138139 $ array = static ::toArray ();
140+
139141 return isset ($ array [$ key ]);
140142 }
141143
@@ -162,8 +164,10 @@ public static function search($value)
162164 */
163165 public static function __callStatic ($ name , $ arguments )
164166 {
165- if (defined ("static:: $ name " )) {
166- return new static (constant ("static:: $ name " ));
167+ if (static ::isValidKey ($ name )) {
168+ $ array = static ::toArray ();
169+
170+ return new static ($ array [$ name ]);
167171 }
168172
169173 throw new \BadMethodCallException ("No static method or enum constant ' $ name' in class " . get_called_class ());
0 commit comments