Skip to content

Commit 1deee22

Browse files
committed
ArrayColumnHelper: Extract new getReturnValueType() method
1 parent 386a54a commit 1deee22

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Type/Php/ArrayColumnHelper.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ public function __construct(
2626
{
2727
}
2828

29-
public function handleAnyArray(Type $arrayType, Type $columnType, ?Type $indexType, Scope $scope): Type
29+
/**
30+
* @return array{Type, TrinaryLogic}
31+
*/
32+
public function getReturnValueType(Type $arrayType, Type $columnType, Scope $scope): array
3033
{
3134
$iterableAtLeastOnce = $arrayType->isIterableAtLeastOnce();
3235
if ($iterableAtLeastOnce->no()) {
33-
return new ConstantArrayType([], []);
36+
return [new NeverType(), $iterableAtLeastOnce];
3437
}
3538

3639
$iterableValueType = $arrayType->getIterableValueType();
@@ -44,11 +47,20 @@ public function handleAnyArray(Type $arrayType, Type $columnType, ?Type $indexTy
4447
}
4548
}
4649

50+
return [$returnValueType, $iterableAtLeastOnce];
51+
}
52+
53+
public function handleAnyArray(Type $arrayType, Type $columnType, ?Type $indexType, Scope $scope): Type
54+
{
55+
[$returnValueType, $iterableAtLeastOnce] = $this->getReturnValueType($arrayType, $columnType, $scope);
56+
4757
if ($returnValueType instanceof NeverType) {
4858
return new ConstantArrayType([], []);
4959
}
5060

5161
if ($indexType !== null) {
62+
$iterableValueType = $arrayType->getIterableValueType();
63+
5264
$type = $this->getOffsetOrProperty($iterableValueType, $indexType, $scope, false);
5365
if ($type !== null) {
5466
$returnKeyType = $type;

0 commit comments

Comments
 (0)