Skip to content

Commit cfedc7b

Browse files
committed
ArrayFilterRule - be consistent about named arguments
1 parent f5b198c commit cfedc7b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/Rules/Functions/ArrayFilterRule.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use PhpParser\Node;
66
use PhpParser\Node\Expr\FuncCall;
7+
use PHPStan\Analyser\ArgumentsNormalizer;
78
use PHPStan\Analyser\Scope;
9+
use PHPStan\Reflection\ParametersAcceptorSelector;
810
use PHPStan\Reflection\ReflectionProvider;
911
use PHPStan\Rules\Rule;
1012
use PHPStan\Rules\RuleErrorBuilder;
@@ -38,13 +40,28 @@ public function processNode(Node $node, Scope $scope): array
3840
return [];
3941
}
4042

41-
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
43+
if (!$this->reflectionProvider->hasFunction($node->name, $scope)) {
44+
return [];
45+
}
46+
47+
$functionReflection = $this->reflectionProvider->getFunction($node->name, $scope);
48+
if ($functionReflection->getName() !== 'array_filter') {
49+
return [];
50+
}
51+
52+
$parametersAcceptor = ParametersAcceptorSelector::selectFromArgs(
53+
$scope,
54+
$node->getArgs(),
55+
$functionReflection->getVariants(),
56+
$functionReflection->getNamedArgumentsVariants(),
57+
);
4258

43-
if ($functionName === null || strtolower($functionName) !== 'array_filter') {
59+
$normalizedFuncCall = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node);
60+
if ($normalizedFuncCall === null) {
4461
return [];
4562
}
4663

47-
$args = $node->getArgs();
64+
$args = $normalizedFuncCall->getArgs();
4865
if (count($args) !== 1) {
4966
return [];
5067
}

0 commit comments

Comments
 (0)