From 9d73f498c9a0ceaa0265ef109dfc99c02578cbee Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Oct 2025 16:32:38 +0700 Subject: [PATCH 1/2] [TypeDeclaration] Allow other functions and sprintf() on AddParamStringTypeFromSprintfUseRector --- .../other_function_and_sprintf.php.inc | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/other_function_and_sprintf.php.inc 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 @@ + +----- + From 41b6159b1cd17a07cbe23217d6872eb09216c68b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Oct 2025 16:35:41 +0700 Subject: [PATCH 2/2] fix --- .../NodeAnalyzer/VariableInSprintfMaskMatcher.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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; }