@@ -134,30 +134,38 @@ private static function getClassKey(): int
134134 * Static method which returns all available types
135135 *
136136 * @return static[]
137- * @noinspection PhpDocMissingThrowsInspection
138137 */
139138 public static function enum ()
140139 {
141140 $ classKey = static ::getClassKey ();
142141
143- if (!isset (self ::$ cache )) {
144- self ::$ cache = static ::getNewStorage ();
142+ if (!isset (static ::$ cache )) {
143+ static ::$ cache = static ::getNewStorage ();
145144 }
146145
147- if (!static ::existsInStorage (self ::$ cache , $ classKey )) {
148- $ methods = static ::getNewStorage ();
146+ if (!static ::existsInStorage (static ::$ cache , $ classKey )) {
147+ static ::build ($ classKey );
148+ }
149149
150- /** @noinspection PhpUnhandledExceptionInspection */
151- foreach ((new ReflectionClass (get_called_class ()))->getMethods (ReflectionMethod::IS_FINAL ) as $ method ) {
152- /** @var static $enum */
153- $ enum = $ method ->invoke (null );
154- static ::putToStorage ($ methods , $ enum ->id (), $ enum );
155- }
150+ return static ::getFromStorage (static ::$ cache , $ classKey );
151+ }
152+
153+ /**
154+ * Build instances of enum options
155+ *
156+ * @param int $classKey
157+ */
158+ protected static function build (int $ classKey )
159+ {
160+ $ methods = static ::getNewStorage ();
156161
157- static ::putToStorage (self ::$ cache , $ classKey , $ methods );
162+ foreach ((new ReflectionClass (static ::class))->getMethods (ReflectionMethod::IS_FINAL ) as $ method ) {
163+ /** @var static $enum */
164+ $ enum = $ method ->invoke (null );
165+ static ::putToStorage ($ methods , $ enum ->id (), $ enum );
158166 }
159167
160- return static ::getFromStorage ( self ::$ cache , $ classKey );
168+ static ::putToStorage ( static ::$ cache , $ classKey, $ methods );
161169 }
162170
163171 /**
@@ -215,7 +223,6 @@ public static function __set_state(array $state): self
215223 * @param string|int $id
216224 * @param string|null $name
217225 * @param null $meta
218- * @noinspection PhpDocMissingThrowsInspection
219226 * @return static
220227 */
221228 protected static function get ($ id , string $ name = null , $ meta = null ): self
@@ -226,19 +233,19 @@ protected static function get($id, string $name = null, $meta = null): self
226233
227234 $ classKey = static ::getClassKey ();
228235
229- if (!isset (self ::$ cache )) {
230- self ::$ cache = static ::getNewStorage ();
236+ if (!isset (static ::$ cache )) {
237+ static ::$ cache = static ::getNewStorage ();
231238 }
232239
233- if (!static ::existsInStorage (self ::$ cache , $ classKey )) {
234- static ::putToStorage (self ::$ cache , $ classKey , static ::getNewStorage ());
240+ if (!static ::existsInStorage (static ::$ cache , $ classKey )) {
241+ static ::putToStorage (static ::$ cache , $ classKey , static ::getNewStorage ());
242+ static ::build ($ classKey );
235243 }
236244
237- $ instances = static ::getFromStorage (self ::$ cache , $ classKey );
245+ $ instances = static ::getFromStorage (static ::$ cache , $ classKey );
238246
239247 if (!static ::existsInStorage ($ instances , $ id )) {
240- /** @noinspection PhpUnhandledExceptionInspection */
241- $ reflection = new ReflectionClass (get_called_class ());
248+ $ reflection = new ReflectionClass (static ::class);
242249 $ instance = $ reflection ->newInstanceWithoutConstructor ();
243250
244251 $ refConstructor = $ reflection ->getConstructor ();
0 commit comments