2727use PHPStan \Type \Generic \TemplateUnionType ;
2828use function array_key_exists ;
2929use function array_key_first ;
30- use function array_map ;
3130use function array_merge ;
3231use function array_slice ;
3332use function array_splice ;
@@ -795,13 +794,9 @@ private static function processArrayTypes(array $arrayTypes): array
795794
796795 /** @var int|float $nextConstantKeyTypeIndex */
797796 $ nextConstantKeyTypeIndex = 1 ;
798- $ constantArraysMap = array_map (
799- static fn (Type $ t ) => $ t ->getConstantArrays (),
800- $ arrayTypes ,
801- );
802797
803- foreach ($ arrayTypes as $ arrayIdx => $ arrayType ) {
804- $ constantArrays = $ constantArraysMap [ $ arrayIdx ] ;
798+ foreach ($ arrayTypes as $ arrayType ) {
799+ $ constantArrays = $ arrayType -> getConstantArrays () ;
805800 $ isConstantArray = $ constantArrays !== [];
806801 if (!$ isConstantArray || !$ arrayType ->isIterableAtLeastOnce ()->no ()) {
807802 $ filledArrays ++;
@@ -816,11 +811,11 @@ private static function processArrayTypes(array $arrayTypes): array
816811 continue ;
817812 }
818813
819- $ constantArrays = $ arrayType ->getConstantArrays ();
820814 foreach ($ constantArrays as $ constantArray ) {
815+ $ valueTypes = $ constantArray ->getValueTypes ();
821816 foreach ($ constantArray ->getKeyTypes () as $ i => $ keyType ) {
822817 $ keyTypesForGeneralArray [] = $ keyType ;
823- $ valueTypesForGeneralArray [] = $ constantArray -> getValueTypes () [$ i ];
818+ $ valueTypesForGeneralArray [] = $ valueTypes [$ i ];
824819
825820 $ keyTypeValue = $ keyType ->getValue ();
826821 if (array_key_exists ($ keyTypeValue , $ constantKeyTypesNumbered )) {
@@ -876,12 +871,11 @@ private static function processArrayTypes(array $arrayTypes): array
876871 ];
877872 }
878873
879- $ reducedArrayTypes = self ::reduceArrays ($ arrayTypes , true );
880-
881- return array_map (
882- static fn (Type $ arrayType ) => self ::intersect ($ arrayType , ...$ accessoryTypes ),
883- self ::optimizeConstantArrays ($ reducedArrayTypes ),
884- );
874+ $ reducedArrayTypes = self ::optimizeConstantArrays (self ::reduceArrays ($ arrayTypes , true ));
875+ foreach ($ reducedArrayTypes as $ idx => $ reducedArray ) {
876+ $ reducedArrayTypes [$ idx ] = self ::intersect ($ reducedArray , ...$ accessoryTypes );
877+ }
878+ return $ reducedArrayTypes ;
885879 }
886880
887881 /**
@@ -915,6 +909,7 @@ private static function optimizeConstantArrays(array $types): array
915909 $ valueTypes = [];
916910 $ keyTypes = [];
917911 $ nextAutoIndex = 0 ;
912+ $ innerValueTypes = $ type ->getValueTypes ();
918913 foreach ($ type ->getKeyTypes () as $ i => $ innerKeyType ) {
919914 if (!$ innerKeyType instanceof ConstantIntegerType) {
920915 $ isList = false ;
@@ -928,8 +923,7 @@ private static function optimizeConstantArrays(array $types): array
928923 $ generalizedKeyType = $ innerKeyType ->generalize (GeneralizePrecision::moreSpecific ());
929924 $ keyTypes [$ generalizedKeyType ->describe (VerbosityLevel::precise ())] = $ generalizedKeyType ;
930925
931- $ innerValueType = $ type ->getValueTypes ()[$ i ];
932- $ generalizedValueType = TypeTraverser::map ($ innerValueType , static function (Type $ type ) use ($ traverse ): Type {
926+ $ generalizedValueType = TypeTraverser::map ($ innerValueTypes [$ i ], static function (Type $ type ) use ($ traverse ): Type {
933927 if ($ type instanceof ArrayType || $ type instanceof ConstantArrayType) {
934928 return TypeCombinator::intersect ($ type , new OversizedArrayType ());
935929 }
0 commit comments