@@ -390,7 +390,9 @@ private function createFromGeneric(GenericTypeNode $type, Context $context): Typ
390390 {
391391 switch (strtolower ($ type ->type ->name )) {
392392 case 'array ' :
393- return $ this ->createArray ($ type ->genericTypes , $ context );
393+ $ genericTypes = array_reverse ($ this ->createTypesByTypeNodes ($ type ->genericTypes , $ context ));
394+
395+ return new Array_ (...$ genericTypes );
394396
395397 case 'non-empty-array ' :
396398 $ genericTypes = array_reverse ($ this ->createTypesByTypeNodes ($ type ->genericTypes , $ context ));
@@ -630,33 +632,6 @@ private function resolveTypedObject(string $type, ?Context $context = null): Obj
630632 return new Object_ ($ this ->fqsenResolver ->resolve ($ type , $ context ));
631633 }
632634
633- /** @param TypeNode[] $typeNodes */
634- private function createArray (array $ typeNodes , Context $ context ): Array_
635- {
636- $ types = array_reverse ($ this ->createTypesByTypeNodes ($ typeNodes , $ context ));
637-
638- if (isset ($ types [1 ]) === false ) {
639- return new Array_ (...$ types );
640- }
641-
642- if ($ this ->validArrayKeyType ($ types [1 ]) || $ types [1 ] instanceof ArrayKey) {
643- return new Array_ (...$ types );
644- }
645-
646- if ($ types [1 ] instanceof Compound && $ types [1 ]->getIterator ()->count () === 2 ) {
647- if ($ this ->validArrayKeyType ($ types [1 ]->get (0 )) && $ this ->validArrayKeyType ($ types [1 ]->get (1 ))) {
648- return new Array_ (...$ types );
649- }
650- }
651-
652- throw new RuntimeException ('An array can have only integers or strings as keys ' );
653- }
654-
655- private function validArrayKeyType (?Type $ type ): bool
656- {
657- return $ type instanceof String_ || $ type instanceof Integer;
658- }
659-
660635 private function parse (TokenIterator $ tokenIterator ): TypeNode
661636 {
662637 try {
0 commit comments