1212use PhpParser \Node \Expr \FuncCall ;
1313use PhpParser \Node \Expr \Ternary ;
1414use PhpParser \Node \Expr \Variable ;
15- use PHPStan \Type \ArrayType ;
16- use PHPStan \Type \Constant \ConstantArrayType ;
15+ use PHPStan \Type \Type ;
1716use Rector \NodeTypeResolver \TypeAnalyzer \ArrayTypeAnalyzer ;
1817use Rector \Php \PhpVersionProvider ;
1918use Rector \Rector \AbstractRector ;
@@ -117,7 +116,7 @@ private function refactorArray(FuncCall $funcCall): ?Array_
117116 }
118117
119118 $ value = $ arg ->value ;
120- if ($ this ->shouldSkipArrayForInvalidTypeOrKeys ($ value )) {
119+ if ($ this ->shouldSkipArrayForInvalidKeys ($ value )) {
121120 return null ;
122121 }
123122
@@ -134,29 +133,16 @@ private function refactorArray(FuncCall $funcCall): ?Array_
134133 return $ array ;
135134 }
136135
137- private function shouldSkipArrayForInvalidTypeOrKeys (Expr $ expr ): bool
136+ private function shouldSkipArrayForInvalidKeys (Expr $ expr ): bool
138137 {
139- // we have no idea what it is → cannot change it
140- if (! $ this ->arrayTypeAnalyzer ->isArrayType ($ expr )) {
141- return true ;
142- }
143-
144- $ arrayStaticType = $ this ->getType ($ expr );
145- if (! $ arrayStaticType instanceof ArrayType && ! $ arrayStaticType instanceof ConstantArrayType) {
146- return true ;
147- }
138+ $ type = $ this ->getType ($ expr );
148139
149- return ! $ this ->isArrayKeyTypeAllowed ($ arrayStaticType );
150- }
151-
152- private function isArrayKeyTypeAllowed (ArrayType |ConstantArrayType $ arrayType ): bool
153- {
154- if ($ arrayType ->getIterableKeyType ()->isInteger ()->yes ()) {
155- return true ;
140+ if ($ type ->getIterableKeyType ()->isInteger ()->yes ()) {
141+ return false ;
156142 }
157143
158144 // php 8.1+ allow mixed key: int, string, and null
159- return $ this ->phpVersionProvider ->isAtLeastPhpVersion (PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS );
145+ return ! $ this ->phpVersionProvider ->isAtLeastPhpVersion (PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS );
160146 }
161147
162148 private function resolveValue (Expr $ expr ): Expr
0 commit comments