diff --git a/src/Rules/StrictCalls/StrictFunctionCallsRule.php b/src/Rules/StrictCalls/StrictFunctionCallsRule.php index 2b6cd899..2ae134b3 100644 --- a/src/Rules/StrictCalls/StrictFunctionCallsRule.php +++ b/src/Rules/StrictCalls/StrictFunctionCallsRule.php @@ -5,7 +5,9 @@ use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Name; +use PHPStan\Analyser\ArgumentsNormalizer; use PHPStan\Analyser\Scope; +use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; @@ -47,11 +49,17 @@ public function processNode(Node $node, Scope $scope): array return []; } - $functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope); - if ($functionName === null) { + if (!$this->reflectionProvider->hasFunction($node->name, $scope)) { return []; } - $functionName = strtolower($functionName); + + $function = $this->reflectionProvider->getFunction($node->name, $scope); + $parametersAcceptor = ParametersAcceptorSelector::selectFromArgs($scope, $node->getArgs(), $function->getVariants()); + $node = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node); + if ($node === null) { + return []; + } + $functionName = strtolower($function->getName()); if (!array_key_exists($functionName, $this->functionArguments)) { return []; } diff --git a/tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php b/tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php index fa08fe7a..95c04ea8 100644 --- a/tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php +++ b/tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -74,4 +75,12 @@ public function testRule(): void ]); } + public function testBug231(): void + { + if (PHP_VERSION_ID < 80100) { + $this->markTestSkipped('Test requires PHP 8.1.'); + } + $this->analyse([__DIR__ . '/data/bug-231.php'], []); + } + } diff --git a/tests/Rules/StrictCalls/data/bug-231.php b/tests/Rules/StrictCalls/data/bug-231.php new file mode 100644 index 00000000..2dac686f --- /dev/null +++ b/tests/Rules/StrictCalls/data/bug-231.php @@ -0,0 +1,18 @@ += 8.1 + +namespace Bug231; + +enum MyEnum: string +{ + case Foo = 'foo'; + case Bar = 'bar'; + case Baz = 'baz'; + + public function isB(): bool + { + return in_array($this, strict: true, haystack: [ + self::Bar, + self::Baz, + ]); + } +}