diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/other_function_and_sprintf.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/other_function_and_sprintf.php.inc new file mode 100644 index 00000000000..44234c77c1a --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/other_function_and_sprintf.php.inc @@ -0,0 +1,35 @@ + +----- + diff --git a/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php b/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php index aaf2f2e2f54..ee6e6d7c0e4 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php +++ b/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php @@ -31,6 +31,9 @@ public function __construct( public function matchMask(ClassMethod|Function_ $functionLike, string $variableName, string $mask): bool { $funcCalls = $this->betterNodeFinder->findInstancesOfScoped((array) $functionLike->stmts, FuncCall::class); + $funcCalls = array_values(array_filter($funcCalls, function (FuncCall $funcCall): bool { + return $this->nodeNameResolver->isName($funcCall->name, 'sprintf'); + })); if (count($funcCalls) !== 1) { return false; @@ -38,10 +41,6 @@ public function matchMask(ClassMethod|Function_ $functionLike, string $variableN $funcCall = $funcCalls[0]; - if (! $this->nodeNameResolver->isName($funcCall->name, 'sprintf')) { - return false; - } - if ($funcCall->isFirstClassCallable()) { return false; }