Skip to content

Commit c4f0089

Browse files
committed
Use ArrayFilterFunctionReturnTypeHelper instead of FuncCall
1 parent 4b6752d commit c4f0089

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Type/Php/ArrayFindFunctionReturnTypeExtension.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Type\Php;
44

55
use PhpParser\Node\Expr\FuncCall;
6-
use PhpParser\Node\Name;
76
use PHPStan\Analyser\Scope;
87
use PHPStan\Reflection\FunctionReflection;
98
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
@@ -15,6 +14,10 @@
1514
final class ArrayFindFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
1615
{
1716

17+
public function __construct(private ArrayFilterFunctionReturnTypeHelper $arrayFilterFunctionReturnTypeHelper)
18+
{
19+
}
20+
1821
public function isFunctionSupported(FunctionReflection $functionReflection): bool
1922
{
2023
return $functionReflection->getName() === 'array_find';
@@ -31,7 +34,10 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
3134
return null;
3235
}
3336

34-
$resultTypes = $scope->getType(new FuncCall(new Name('\array_filter'), $functionCall->getArgs()));
37+
$arrayArg = $functionCall->getArgs()[0]->value ?? null;
38+
$callbackArg = $functionCall->getArgs()[1]->value ?? null;
39+
40+
$resultTypes = $this->arrayFilterFunctionReturnTypeHelper->getType($scope, $arrayArg, $callbackArg, null);
3541
$resultType = TypeCombinator::union(...array_map(static fn ($type) => $type->getIterableValueType(), $resultTypes->getArrays()));
3642

3743
return $resultTypes->isIterableAtLeastOnce()->yes() ? $resultType : TypeCombinator::addNull($resultType);

0 commit comments

Comments
 (0)