@@ -70,7 +70,7 @@ public function getKey()
70
70
*/
71
71
public function __toString ()
72
72
{
73
- return (string ) $ this ->value ;
73
+ return (string )$ this ->value ;
74
74
}
75
75
76
76
/**
@@ -108,7 +108,7 @@ public static function toArray()
108
108
{
109
109
$ class = get_called_class ();
110
110
if (!array_key_exists ($ class , self ::$ cache )) {
111
- $ reflection = new \ReflectionClass ($ class );
111
+ $ reflection = new \ReflectionClass ($ class );
112
112
self ::$ cache [$ class ] = $ reflection ->getConstants ();
113
113
}
114
114
@@ -119,6 +119,7 @@ public static function toArray()
119
119
* Check if is valid enum value
120
120
*
121
121
* @param $value
122
+ *
122
123
* @return bool
123
124
*/
124
125
public static function isValid ($ value )
@@ -136,6 +137,7 @@ public static function isValid($value)
136
137
public static function isValidKey ($ key )
137
138
{
138
139
$ array = static ::toArray ();
140
+
139
141
return isset ($ array [$ key ]);
140
142
}
141
143
@@ -162,8 +164,10 @@ public static function search($value)
162
164
*/
163
165
public static function __callStatic ($ name , $ arguments )
164
166
{
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 ]);
167
171
}
168
172
169
173
throw new \BadMethodCallException ("No static method or enum constant ' $ name' in class " . get_called_class ());
0 commit comments