Skip to content

Commit

Permalink
ArrayColumnHelper: Extract new getReturnValueType() method
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jan 16, 2025
1 parent eacba20 commit 44ac0f2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Type/Php/ArrayColumnHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ public function __construct(
{
}

public function handleAnyArray(Type $arrayType, Type $columnType, ?Type $indexType, Scope $scope): Type
/**
* @return array{Type, TrinaryLogic}
*/
public function getReturnValueType(Type $arrayType, Type $columnType, Scope $scope): array
{
$iterableAtLeastOnce = $arrayType->isIterableAtLeastOnce();
if ($iterableAtLeastOnce->no()) {
return new ConstantArrayType([], []);
return [new NeverType(), $iterableAtLeastOnce];
}

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

return [$returnValueType, $iterableAtLeastOnce];
}

public function handleAnyArray(Type $arrayType, Type $columnType, ?Type $indexType, Scope $scope): Type
{
[$returnValueType, $iterableAtLeastOnce] = $this->getReturnValueType($arrayType, $columnType, $scope);

if ($returnValueType instanceof NeverType) {
return new ConstantArrayType([], []);
}

if ($indexType !== null) {
$iterableValueType = $arrayType->getIterableValueType();

$type = $this->getOffsetOrProperty($iterableValueType, $indexType, $scope, false);
if ($type !== null) {
$returnKeyType = $type;
Expand Down

0 comments on commit 44ac0f2

Please sign in to comment.