33namespace PHPStan \Rules \Methods ;
44
55use PhpParser \Node ;
6+ use PhpParser \Node \Expr \BinaryOp \Identical ;
67use PhpParser \Node \Expr \MethodCall ;
8+ use PhpParser \Node \Scalar \String_ ;
79use PHPStan \Analyser \Scope ;
810use PHPStan \Internal \SprintfHelper ;
911use PHPStan \Reflection \ParametersAcceptorSelector ;
1012use PHPStan \Rules \FunctionCallParametersCheck ;
1113use PHPStan \Rules \IdentifierRuleError ;
1214use PHPStan \Rules \Rule ;
1315use PHPStan \Type \Constant \ConstantStringType ;
16+ use function array_column ;
1417use function array_map ;
1518use function array_merge ;
1619
@@ -36,14 +39,22 @@ public function processNode(Node $node, Scope $scope): array
3639 {
3740 $ errors = [];
3841 if ($ node ->name instanceof Node \Identifier) {
39- $ methodNames = [$ node ->name ->name ];
42+ $ methodNameScopes = [$ node ->name ->name => $ scope ];
4043 } 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+
4354 }
4455
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 ));
4758 }
4859
4960 return $ errors ;
0 commit comments