From 44ac0f27ee360a45afb7b4acb887066197879acb Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 16 Jan 2025 16:21:11 +0100 Subject: [PATCH] ArrayColumnHelper: Extract new getReturnValueType() method --- src/Type/Php/ArrayColumnHelper.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Type/Php/ArrayColumnHelper.php b/src/Type/Php/ArrayColumnHelper.php index dd0dd898ad..01039d0716 100644 --- a/src/Type/Php/ArrayColumnHelper.php +++ b/src/Type/Php/ArrayColumnHelper.php @@ -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(); @@ -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;