Skip to content

Commit 3a67365

Browse files
committed
Merge branch '1.5.x' into 1.6.x
2 parents 50aab8d + 5ae7a3d commit 3a67365

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/Rules/StrictCalls/StrictFunctionCallsRule.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use PhpParser\Node;
66
use PhpParser\Node\Expr\FuncCall;
77
use PhpParser\Node\Name;
8+
use PHPStan\Analyser\ArgumentsNormalizer;
89
use PHPStan\Analyser\Scope;
10+
use PHPStan\Reflection\ParametersAcceptorSelector;
911
use PHPStan\Reflection\ReflectionProvider;
1012
use PHPStan\Rules\Rule;
1113
use PHPStan\Rules\RuleErrorBuilder;
@@ -47,11 +49,17 @@ public function processNode(Node $node, Scope $scope): array
4749
return [];
4850
}
4951

50-
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
51-
if ($functionName === null) {
52+
if (!$this->reflectionProvider->hasFunction($node->name, $scope)) {
5253
return [];
5354
}
54-
$functionName = strtolower($functionName);
55+
56+
$function = $this->reflectionProvider->getFunction($node->name, $scope);
57+
$parametersAcceptor = ParametersAcceptorSelector::selectFromArgs($scope, $node->getArgs(), $function->getVariants());
58+
$node = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node);
59+
if ($node === null) {
60+
return [];
61+
}
62+
$functionName = strtolower($function->getName());
5563
if (!array_key_exists($functionName, $this->functionArguments)) {
5664
return [];
5765
}

tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\Rules\Rule;
66
use PHPStan\Testing\RuleTestCase;
7+
use const PHP_VERSION_ID;
78

89
/**
910
* @extends RuleTestCase<StrictFunctionCallsRule>
@@ -74,4 +75,12 @@ public function testRule(): void
7475
]);
7576
}
7677

78+
public function testBug231(): void
79+
{
80+
if (PHP_VERSION_ID < 80100) {
81+
$this->markTestSkipped('Test requires PHP 8.1.');
82+
}
83+
$this->analyse([__DIR__ . '/data/bug-231.php'], []);
84+
}
85+
7786
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php // lint >= 8.1
2+
3+
namespace Bug231;
4+
5+
enum MyEnum: string
6+
{
7+
case Foo = 'foo';
8+
case Bar = 'bar';
9+
case Baz = 'baz';
10+
11+
public function isB(): bool
12+
{
13+
return in_array($this, strict: true, haystack: [
14+
self::Bar,
15+
self::Baz,
16+
]);
17+
}
18+
}

0 commit comments

Comments
 (0)