Skip to content

Commit 0cbd46b

Browse files
committed
ArrayColumnHelper: Extract new getReturnIndexType() method
1 parent 6e00332 commit 0cbd46b

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/Type/Php/ArrayColumnHelper.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,35 @@ public function getReturnValueType(Type $arrayType, Type $columnType, Scope $sco
5050
return [$returnValueType, $iterableAtLeastOnce];
5151
}
5252

53-
public function handleAnyArray(Type $arrayType, Type $columnType, ?Type $indexType, Scope $scope): Type
53+
public function getReturnIndexType(Type $arrayType, ?Type $indexType, Scope $scope): Type
5454
{
55-
[$returnValueType, $iterableAtLeastOnce] = $this->getReturnValueType($arrayType, $columnType, $scope);
56-
if ($returnValueType instanceof NeverType) {
57-
return new ConstantArrayType([], []);
58-
}
59-
6055
if ($indexType !== null) {
6156
$iterableValueType = $arrayType->getIterableValueType();
6257

6358
$type = $this->getOffsetOrProperty($iterableValueType, $indexType, $scope, false);
6459
if ($type !== null) {
65-
$returnKeyType = $type;
66-
} else {
67-
$type = $this->getOffsetOrProperty($iterableValueType, $indexType, $scope, true);
68-
if ($type !== null) {
69-
$returnKeyType = TypeCombinator::union($type, new IntegerType());
70-
} else {
71-
$returnKeyType = new IntegerType();
72-
}
60+
return $type;
7361
}
74-
} else {
75-
$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+
return new IntegerType();
69+
}
70+
71+
return new IntegerType();
72+
}
73+
74+
public function handleAnyArray(Type $arrayType, Type $columnType, ?Type $indexType, Scope $scope): Type
75+
{
76+
[$returnValueType, $iterableAtLeastOnce] = $this->getReturnValueType($arrayType, $columnType, $scope);
77+
if ($returnValueType instanceof NeverType) {
78+
return new ConstantArrayType([], []);
7679
}
7780

81+
$returnKeyType = $this->getReturnIndexType($arrayType, $indexType, $scope);
7882
$returnType = new ArrayType($this->castToArrayKeyType($returnKeyType), $returnValueType);
7983

8084
if ($iterableAtLeastOnce->yes()) {

0 commit comments

Comments
 (0)