@@ -391,7 +391,9 @@ private function createFromGeneric(GenericTypeNode $type, Context $context): Typ
391391 {
392392 switch (strtolower ($ type ->type ->name )) {
393393 case 'array ' :
394- return $ this ->createArray ($ type ->genericTypes , $ context );
394+ $ genericTypes = array_reverse ($ this ->createTypesByTypeNodes ($ type ->genericTypes , $ context ));
395+
396+ return new Array_ (...$ genericTypes );
395397
396398 case 'non-empty-array ' :
397399 $ genericTypes = array_reverse ($ this ->createTypesByTypeNodes ($ type ->genericTypes , $ context ));
@@ -612,33 +614,6 @@ private function resolveTypedObject(string $type, ?Context $context = null): Obj
612614 return new Object_ ($ this ->fqsenResolver ->resolve ($ type , $ context ));
613615 }
614616
615- /** @param TypeNode[] $typeNodes */
616- private function createArray (array $ typeNodes , Context $ context ): Array_
617- {
618- $ types = array_reverse ($ this ->createTypesByTypeNodes ($ typeNodes , $ context ));
619-
620- if (isset ($ types [1 ]) === false ) {
621- return new Array_ (...$ types );
622- }
623-
624- if ($ this ->validArrayKeyType ($ types [1 ]) || $ types [1 ] instanceof ArrayKey) {
625- return new Array_ (...$ types );
626- }
627-
628- if ($ types [1 ] instanceof Compound && $ types [1 ]->getIterator ()->count () === 2 ) {
629- if ($ this ->validArrayKeyType ($ types [1 ]->get (0 )) && $ this ->validArrayKeyType ($ types [1 ]->get (1 ))) {
630- return new Array_ (...$ types );
631- }
632- }
633-
634- throw new RuntimeException ('An array can have only integers or strings as keys ' );
635- }
636-
637- private function validArrayKeyType (?Type $ type ): bool
638- {
639- return $ type instanceof String_ || $ type instanceof Integer;
640- }
641-
642617 private function parse (TokenIterator $ tokenIterator ): TypeNode
643618 {
644619 try {
0 commit comments