Skip to content

Commit 6e00332

Browse files
committed
ArrayColumnHelper: Extract new getReturnValueType() method
1 parent 39e71df commit 6e00332

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Type/Php/ArrayColumnHelper.php

Lines changed: 13 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,19 @@ 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);
4756
if ($returnValueType instanceof NeverType) {
4857
return new ConstantArrayType([], []);
4958
}
5059

5160
if ($indexType !== null) {
61+
$iterableValueType = $arrayType->getIterableValueType();
62+
5263
$type = $this->getOffsetOrProperty($iterableValueType, $indexType, $scope, false);
5364
if ($type !== null) {
5465
$returnKeyType = $type;

0 commit comments

Comments
 (0)