diff --git a/src/Type/Php/ArrayColumnHelper.php b/src/Type/Php/ArrayColumnHelper.php index 01039d0716..a0796febf4 100644 --- a/src/Type/Php/ArrayColumnHelper.php +++ b/src/Type/Php/ArrayColumnHelper.php @@ -50,32 +50,33 @@ public function getReturnValueType(Type $arrayType, Type $columnType, Scope $sco return [$returnValueType, $iterableAtLeastOnce]; } - public function handleAnyArray(Type $arrayType, Type $columnType, ?Type $indexType, Scope $scope): Type + public function getReturnIndexType(Type $arrayType, ?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; - } else { - $type = $this->getOffsetOrProperty($iterableValueType, $indexType, $scope, true); - if ($type !== null) { - $returnKeyType = TypeCombinator::union($type, new IntegerType()); - } else { - $returnKeyType = new IntegerType(); - } + return $type; } - } else { - $returnKeyType = new IntegerType(); + + $type = $this->getOffsetOrProperty($iterableValueType, $indexType, $scope, true); + if ($type !== null) { + return TypeCombinator::union($type, new IntegerType()); + } + } + + return new IntegerType(); + } + + 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([], []); } + $returnKeyType = $this->getReturnIndexType($arrayType, $indexType, $scope); $returnType = new ArrayType($this->castToArrayKeyType($returnKeyType), $returnValueType); if ($iterableAtLeastOnce->yes()) {