Skip to content

Commit 9e84671

Browse files
committed
Easier solution
1 parent 88d9fcc commit 9e84671

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

src/Type/Php/ArraySliceFunctionReturnTypeExtension.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use PhpParser\Node\Expr\FuncCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\FunctionReflection;
8-
use PHPStan\Type\Accessory\AccessoryArrayListType;
9-
use PHPStan\Type\Accessory\NonEmptyArrayType;
8+
use PHPStan\Type\Constant\ConstantArrayType;
109
use PHPStan\Type\Constant\ConstantIntegerType;
1110
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
1211
use PHPStan\Type\Type;
@@ -52,14 +51,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
5251
}
5352

5453
if ($valueType->isIterableAtLeastOnce()->yes()) {
55-
$valueType = $valueType->toArray();
56-
if ((new NonEmptyArrayType())->isSuperTypeOf($valueType)->yes()) {
57-
$arrays = $valueType->getArrays();
58-
if (count($arrays) === 1) {
59-
$newArrayType = $arrays[0];
60-
return $valueType->isList()->yes() ? AccessoryArrayListType::intersectWith($newArrayType) : $newArrayType;
61-
}
62-
}
54+
return TypeCombinator::union($valueType, new ConstantArrayType([], []));
6355
}
6456

6557
return $valueType;

0 commit comments

Comments
 (0)