@@ -34,21 +34,21 @@ abstract class Enum
3434 *
3535 * @var array ["$class" => ["$name" => $value, ...], ...]
3636 */
37- private static $ constants = array () ;
37+ private static $ constants = [] ;
3838
3939 /**
4040 * A List of available enumerator names by enumeration class
4141 *
4242 * @var array ["$class" => ["$name0", ...], ...]
4343 */
44- private static $ names = array () ;
44+ private static $ names = [] ;
4545
4646 /**
4747 * Already instantiated enumerators
4848 *
4949 * @var array ["$class" => ["$name" => $instance, ...], ...]
5050 */
51- private static $ instances = array () ;
51+ private static $ instances = [] ;
5252
5353 /**
5454 * Constructor
@@ -162,20 +162,20 @@ final public function is($enumerator)
162162 }
163163
164164 /**
165- * Get an enumerator instance of the given value or instance
165+ * Get an enumerator instance of the given enumerator value or instance
166166 *
167- * @param static|null|bool|int|float|string $value
167+ * @param static|null|bool|int|float|string $enumerator
168168 * @return static
169169 * @throws InvalidArgumentException On an unknwon or invalid value
170170 * @throws LogicException On ambiguous constant values
171171 */
172- final public static function get ($ value )
172+ final public static function get ($ enumerator )
173173 {
174- if ($ value instanceof static && \get_class ($ value ) === static ::class) {
175- return $ value ;
174+ if ($ enumerator instanceof static && \get_class ($ enumerator ) === static ::class) {
175+ return $ enumerator ;
176176 }
177177
178- return static ::byValue ($ value );
178+ return static ::byValue ($ enumerator );
179179 }
180180
181181 /**
@@ -188,8 +188,7 @@ final public static function get($value)
188188 */
189189 final public static function byValue ($ value )
190190 {
191- $ class = static ::class;
192- $ constants = self ::detectConstants ($ class );
191+ $ constants = self ::detectConstants (static ::class);
193192 $ name = \array_search ($ value , $ constants , true );
194193 if ($ name === false ) {
195194 $ message = \is_scalar ($ value )
@@ -198,11 +197,11 @@ final public static function byValue($value)
198197 throw new InvalidArgumentException ($ message );
199198 }
200199
201- if (!isset (self ::$ instances [$ class ][$ name ])) {
202- self ::$ instances [$ class ][$ name ] = new $ class ($ constants [$ name ]);
200+ if (!isset (self ::$ instances [static :: class][$ name ])) {
201+ self ::$ instances [static :: class][$ name ] = new static ($ constants [$ name ]);
203202 }
204203
205- return self ::$ instances [$ class ][$ name ];
204+ return self ::$ instances [static :: class][$ name ];
206205 }
207206
208207 /**
@@ -215,18 +214,17 @@ final public static function byValue($value)
215214 */
216215 final public static function byName ($ name )
217216 {
218- $ name = (string ) $ name ;
219- $ class = static ::class;
220- if (isset (self ::$ instances [$ class ][$ name ])) {
221- return self ::$ instances [$ class ][$ name ];
217+ $ name = (string ) $ name ;
218+ if (isset (self ::$ instances [static ::class][$ name ])) {
219+ return self ::$ instances [static ::class][$ name ];
222220 }
223221
224- $ const = $ class . ':: ' . $ name ;
222+ $ const = static :: class . ':: ' . $ name ;
225223 if (!\defined ($ const )) {
226224 throw new InvalidArgumentException ($ const . ' not defined ' );
227225 }
228226
229- return self ::$ instances [$ class ][$ name ] = new $ class (\constant ($ const ));
227+ return self ::$ instances [static :: class][$ name ] = new static (\constant ($ const ));
230228 }
231229
232230 /**
@@ -239,27 +237,26 @@ final public static function byName($name)
239237 */
240238 final public static function byOrdinal ($ ordinal )
241239 {
242- $ ordinal = (int ) $ ordinal ;
243- $ class = static ::class;
240+ $ ordinal = (int ) $ ordinal ;
244241
245- if (!isset (self ::$ names [$ class ])) {
246- self ::detectConstants ($ class );
242+ if (!isset (self ::$ names [static :: class])) {
243+ self ::detectConstants (static :: class);
247244 }
248245
249- if (!isset (self ::$ names [$ class ][$ ordinal ])) {
246+ if (!isset (self ::$ names [static :: class][$ ordinal ])) {
250247 throw new InvalidArgumentException (\sprintf (
251248 'Invalid ordinal number, must between 0 and %s ' ,
252- \count (self ::$ names [$ class ]) - 1
249+ \count (self ::$ names [static :: class]) - 1
253250 ));
254251 }
255252
256- $ name = self ::$ names [$ class ][$ ordinal ];
257- if (isset (self ::$ instances [$ class ][$ name ])) {
258- return self ::$ instances [$ class ][$ name ];
253+ $ name = self ::$ names [static :: class][$ ordinal ];
254+ if (isset (self ::$ instances [static :: class][$ name ])) {
255+ return self ::$ instances [static :: class][$ name ];
259256 }
260257
261- $ const = $ class . ':: ' . $ name ;
262- return self ::$ instances [$ class ][$ name ] = new $ class (\constant ($ const ), $ ordinal );
258+ $ const = static :: class . ':: ' . $ name ;
259+ return self ::$ instances [static :: class][$ name ] = new static (\constant ($ const ), $ ordinal );
263260 }
264261
265262 /**
@@ -305,7 +302,7 @@ final public static function getNames()
305302 final public static function getOrdinals ()
306303 {
307304 $ count = \count (self ::detectConstants (static ::class));
308- return $ count === 0 ? array () : \range (0 , $ count - 1 );
305+ return $ count === 0 ? [] : \range (0 , $ count - 1 );
309306 }
310307
311308 /**
@@ -346,10 +343,10 @@ private static function detectConstants($class)
346343 {
347344 if (!isset (self ::$ constants [$ class ])) {
348345 $ reflection = new ReflectionClass ($ class );
349- $ constants = array () ;
346+ $ constants = [] ;
350347
351348 do {
352- $ scopeConstants = array () ;
349+ $ scopeConstants = [] ;
353350 if (PHP_VERSION_ID >= 70100 ) {
354351 // Since PHP-7.1 visibility modifiers are allowed for class constants
355352 // for enumerations we are only interested in public once.
@@ -367,7 +364,7 @@ private static function detectConstants($class)
367364 } while (($ reflection = $ reflection ->getParentClass ()) && $ reflection ->name !== __CLASS__ );
368365
369366 // Detect ambiguous values and report names
370- $ ambiguous = array () ;
367+ $ ambiguous = [] ;
371368 foreach ($ constants as $ value ) {
372369 $ names = \array_keys ($ constants , $ value , true );
373370 if (\count ($ names ) > 1 ) {
0 commit comments