1212use PHPStan \ShouldNotHappenException ;
1313use PHPStan \TrinaryLogic ;
1414use PHPStan \Type \Accessory \AccessoryArrayListType ;
15- use PHPStan \Type \Accessory \AccessoryDecimalIntegerStringType ;
1615use PHPStan \Type \Accessory \HasOffsetValueType ;
1716use PHPStan \Type \Accessory \NonEmptyArrayType ;
1817use PHPStan \Type \Constant \ConstantArrayType ;
3332use PHPStan \Type \Traits \UndecidedComparisonTypeTrait ;
3433use function array_merge ;
3534use function count ;
36- use function in_array ;
3735use function sprintf ;
3836
3937/** @api */
@@ -52,15 +50,11 @@ class ArrayType implements Type
5250 /** @api */
5351 public function __construct (Type $ keyType , private Type $ itemType )
5452 {
55- $ desc = $ keyType ->describe (VerbosityLevel::value ());
56- if (in_array ($ desc , ['(int|string) ' , '(int|non-decimal-int-string) ' ], true )) {
53+ if ($ keyType ->describe (VerbosityLevel::value ()) === '(int|string) ' ) {
5754 $ keyType = new MixedType ();
5855 }
5956 if ($ keyType instanceof StrictMixedType && !$ keyType instanceof TemplateStrictMixedType) {
60- $ keyType = new UnionType ([
61- new StringType (),
62- new IntegerType (),
63- ]);
57+ $ keyType = new UnionType ([new StringType (), new IntegerType ()]);
6458 }
6559
6660 $ this ->keyType = $ keyType ;
@@ -121,7 +115,7 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
121115 {
122116 if ($ type instanceof self || $ type instanceof ConstantArrayType) {
123117 return $ this ->getItemType ()->isSuperTypeOf ($ type ->getItemType ())
124- ->and ($ this ->getKeyType ()->isSuperTypeOf ($ type ->getKeyType ()));
118+ ->and ($ this ->getIterableKeyType ()->isSuperTypeOf ($ type ->getIterableKeyType ()));
125119 }
126120
127121 if ($ type instanceof CompoundType) {
@@ -206,10 +200,10 @@ public function getIterableKeyType(): Type
206200 {
207201 $ keyType = $ this ->keyType ;
208202 if ($ keyType instanceof MixedType && !$ keyType instanceof TemplateMixedType) {
209- return new BenevolentUnionType ([new IntegerType (), new IntersectionType ([ new StringType (), new AccessoryDecimalIntegerStringType (inverse: true )] )]);
203+ return new BenevolentUnionType ([new IntegerType (), new StringType ()]);
210204 }
211205 if ($ keyType instanceof StrictMixedType) {
212- return new BenevolentUnionType ([new IntegerType (), new IntersectionType ([ new StringType (), new AccessoryDecimalIntegerStringType (inverse: true )] )]);
206+ return new BenevolentUnionType ([new IntegerType (), new StringType ()]);
213207 }
214208
215209 return $ keyType ;
0 commit comments