Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f07cf71

Browse files
committedJan 16, 2025·
ArrayColumnHelper: Extract new getReturnIndexType() method
1 parent 1deee22 commit f07cf71

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed
 

Diff for: ‎src/Type/Php/ArrayColumnHelper.php

+18-17
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,33 @@ 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-
57-
if ($returnValueType instanceof NeverType) {
58-
return new ConstantArrayType([], []);
59-
}
60-
6155
if ($indexType !== null) {
6256
$iterableValueType = $arrayType->getIterableValueType();
6357

6458
$type = $this->getOffsetOrProperty($iterableValueType, $indexType, $scope, false);
6559
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;
7461
}
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([], []);
7777
}
7878

79+
$returnKeyType = $this->getReturnIndexType($arrayType, $indexType, $scope);
7980
$returnType = new ArrayType($this->castToArrayKeyType($returnKeyType), $returnValueType);
8081

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

0 commit comments

Comments
 (0)
Please sign in to comment.