11<?php
22
3+ declare (strict_types=1 );
4+
35namespace vjik \enum ;
46
57use LogicException ;
1315 */
1416abstract class Enum
1517{
16-
17- /**
18- * @var array
19- */
20- protected static $ _cacheItems = [];
21-
22- /**
23- * @var array
24- */
25- protected static $ _cacheInstances = [];
18+ protected static array $ cacheItems = [];
19+ protected static array $ cacheInstances = [];
2620
2721 /**
2822 * @var int|string
2923 */
3024 protected $ id ;
3125
32- /**
33- * @var string
34- */
3526 protected $ name ;
3627
3728 /**
@@ -56,13 +47,13 @@ public function __construct($id)
5647 * @throws UnexpectedValueException
5748 * @since 2.1.0
5849 */
59- public static function get ($ id )
50+ public static function get ($ id ): self
6051 {
6152 $ key = get_called_class () . '~ ' . $ id ;
62- if (empty (static ::$ _cacheInstances [$ key ])) {
63- static ::$ _cacheInstances [$ key ] = new static ($ id );
53+ if (empty (static ::$ cacheInstances [$ key ])) {
54+ static ::$ cacheInstances [$ key ] = new static ($ id );
6455 }
65- return static ::$ _cacheInstances [$ key ];
56+ return static ::$ cacheInstances [$ key ];
6657 }
6758
6859 /**
@@ -72,7 +63,7 @@ public static function get($id)
7263 * @return bool
7364 * @throws ReflectionException
7465 */
75- public static function isValid ($ id , array $ filter = [])
66+ public static function isValid ($ id , array $ filter = []): bool
7667 {
7768 return in_array ($ id , static ::toIds ($ filter ), true );
7869 }
@@ -83,10 +74,10 @@ public static function isValid($id, array $filter = [])
8374 * @return array enum-значение - ключ, массив с данными - значение
8475 * @throws ReflectionException
8576 */
86- public static function toArray (array $ filter = [])
77+ public static function toArray (array $ filter = []): array
8778 {
8879 $ class = get_called_class ();
89- if (!array_key_exists ($ class , static ::$ _cacheItems )) {
80+ if (!array_key_exists ($ class , static ::$ cacheItems )) {
9081 $ reflection = new \ReflectionClass ($ class );
9182 if (is_callable ([$ class , 'items ' ])) {
9283 /** @noinspection PhpUndefinedMethodInspection */
@@ -103,9 +94,9 @@ public static function toArray(array $filter = [])
10394 }
10495 $ items [$ constant ]['id ' ] = $ constant ;
10596 }
106- static ::$ _cacheItems [$ class ] = $ items ;
97+ static ::$ cacheItems [$ class ] = $ items ;
10798 }
108- $ items = array_filter (static ::$ _cacheItems [$ class ], function ($ item ) use ($ class , $ filter ) {
99+ $ items = array_filter (static ::$ cacheItems [$ class ], function ($ item ) use ($ class , $ filter ) {
109100 foreach ($ filter as $ key => $ filterItem ) {
110101 if (is_int ($ key )) {
111102 $ operator = $ filterItem [0 ];
@@ -177,7 +168,7 @@ public static function toArray(array $filter = [])
177168 * @return array
178169 * @throws ReflectionException
179170 */
180- public static function toIds (array $ filter = [])
171+ public static function toIds (array $ filter = []): array
181172 {
182173 $ ids = [];
183174 foreach (static ::toArray ($ filter ) as $ item ) {
@@ -192,7 +183,7 @@ public static function toIds(array $filter = [])
192183 * @return array enum-значение - ключ, имя - значение
193184 * @throws ReflectionException
194185 */
195- public static function toList (array $ filter = [])
186+ public static function toList (array $ filter = []): array
196187 {
197188 $ list = [];
198189 foreach (static ::toArray ($ filter ) as $ id => $ data ) {
@@ -207,7 +198,7 @@ public static function toList(array $filter = [])
207198 * @return array
208199 * @throws ReflectionException
209200 */
210- public static function toObjects (array $ filter = [])
201+ public static function toObjects (array $ filter = []): array
211202 {
212203 $ objects = [];
213204 foreach (static ::toIds ($ filter ) as $ id ) {
0 commit comments