@@ -50,32 +50,33 @@ public function getReturnValueType(Type $arrayType, Type $columnType, Scope $sco
50
50
return [$ returnValueType , $ iterableAtLeastOnce ];
51
51
}
52
52
53
- public function handleAnyArray (Type $ arrayType, Type $ columnType , ?Type $ indexType , Scope $ scope ): Type
53
+ public function getReturnIndexType (Type $ arrayType , ?Type $ indexType , Scope $ scope ): Type
54
54
{
55
- [$ returnValueType , $ iterableAtLeastOnce ] = $ this ->getReturnValueType ($ arrayType , $ columnType , $ scope );
56
-
57
- if ($ returnValueType instanceof NeverType) {
58
- return new ConstantArrayType ([], []);
59
- }
60
-
61
55
if ($ indexType !== null ) {
62
56
$ iterableValueType = $ arrayType ->getIterableValueType ();
63
57
64
58
$ type = $ this ->getOffsetOrProperty ($ iterableValueType , $ indexType , $ scope , false );
65
59
if ($ type !== null ) {
66
- $ returnKeyType = $ type ;
67
- } else {
68
- $ type = $ this ->getOffsetOrProperty ($ iterableValueType , $ indexType , $ scope , true );
69
- if ($ type !== null ) {
70
- $ returnKeyType = TypeCombinator::union ($ type , new IntegerType ());
71
- } else {
72
- $ returnKeyType = new IntegerType ();
73
- }
60
+ return $ type ;
74
61
}
75
- } else {
76
- $ returnKeyType = new IntegerType ();
62
+
63
+ $ type = $ this ->getOffsetOrProperty ($ iterableValueType , $ indexType , $ scope , true );
64
+ if ($ type !== null ) {
65
+ return TypeCombinator::union ($ type , new IntegerType ());
66
+ }
67
+ }
68
+
69
+ return new IntegerType ();
70
+ }
71
+
72
+ public function handleAnyArray (Type $ arrayType , Type $ columnType , ?Type $ indexType , Scope $ scope ): Type
73
+ {
74
+ [$ returnValueType , $ iterableAtLeastOnce ] = $ this ->getReturnValueType ($ arrayType , $ columnType , $ scope );
75
+ if ($ returnValueType instanceof NeverType) {
76
+ return new ConstantArrayType ([], []);
77
77
}
78
78
79
+ $ returnKeyType = $ this ->getReturnIndexType ($ arrayType , $ indexType , $ scope );
79
80
$ returnType = new ArrayType ($ this ->castToArrayKeyType ($ returnKeyType ), $ returnValueType );
80
81
81
82
if ($ iterableAtLeastOnce ->yes ()) {
0 commit comments