3
3
namespace PHPStan \Rules \Methods ;
4
4
5
5
use PhpParser \Node ;
6
+ use PhpParser \Node \Expr \BinaryOp \Identical ;
6
7
use PhpParser \Node \Expr \MethodCall ;
8
+ use PhpParser \Node \Scalar \String_ ;
7
9
use PHPStan \Analyser \Scope ;
8
10
use PHPStan \Internal \SprintfHelper ;
9
11
use PHPStan \Reflection \ParametersAcceptorSelector ;
10
12
use PHPStan \Rules \FunctionCallParametersCheck ;
11
13
use PHPStan \Rules \IdentifierRuleError ;
12
14
use PHPStan \Rules \Rule ;
13
15
use PHPStan \Type \Constant \ConstantStringType ;
16
+ use function array_column ;
14
17
use function array_map ;
15
18
use function array_merge ;
16
19
@@ -36,14 +39,22 @@ public function processNode(Node $node, Scope $scope): array
36
39
{
37
40
$ errors = [];
38
41
if ($ node ->name instanceof Node \Identifier) {
39
- $ methodNames = [$ node ->name ->name ];
42
+ $ methodNameScopes = [$ node ->name ->name => $ scope ];
40
43
} else {
41
- $ callType = $ scope ->getType ($ node ->name );
42
- $ methodNames = array_map (static fn (ConstantStringType $ type ): string => $ type ->getValue (), $ callType ->getConstantStrings ());
44
+ $ nameType = $ scope ->getType ($ node ->name );
45
+ $ methodNames = array_map (static fn (ConstantStringType $ type ): string => $ type ->getValue (), $ nameType ->getConstantStrings ());
46
+ $ methodNameScopes = array_column (array_map (
47
+ static fn (ConstantStringType $ constantString ) => [
48
+ $ name = $ constantString ->getValue (),
49
+ $ scope ->filterByTruthyValue (new Identical ($ node ->name , new String_ ($ name ))),
50
+ ],
51
+ $ nameType ->getConstantStrings (),
52
+ ), 1 , 0 );
53
+
43
54
}
44
55
45
- foreach ($ methodNames as $ methodName ) {
46
- $ errors = array_merge ($ errors , $ this ->processSingleMethodCall ($ scope , $ node , $ methodName ));
56
+ foreach ($ methodNameScopes as $ methodName => $ methodScope ) {
57
+ $ errors = array_merge ($ errors , $ this ->processSingleMethodCall ($ methodScope , $ node , $ methodName ));
47
58
}
48
59
49
60
return $ errors ;
0 commit comments