From 1f2dd8227b45c11508bd1bffb733e24050799531 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Oct 2025 15:17:14 +0700 Subject: [PATCH 1/2] [TypeDeclaration] Skip possible int and falsy on AddParamStringTypeFromSprintfUseRector --- .../Fixture/skip_possible_int.php.inc | 18 ++++++++++++++++++ .../Fixture/skip_with_empty_check.php.inc | 16 ++++++++++++++++ .../VariableInSprintfMaskMatcher.php | 9 +++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/skip_possible_int.php.inc create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/skip_with_empty_check.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/skip_possible_int.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/skip_possible_int.php.inc new file mode 100644 index 00000000000..0c84793eaf9 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/skip_possible_int.php.inc @@ -0,0 +1,18 @@ + 'Fatal error', + \E_PARSE => 'Parse error', + \E_USER_WARNING, \E_WARNING, \E_COMPILE_WARNING => 'Warning', + \E_USER_NOTICE, \E_NOTICE => 'Notice', + \E_USER_DEPRECATED, \E_DEPRECATED => 'Deprecated', + default => sprintf('Unknown (%s)', $errno), + }; + } +} \ No newline at end of file diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/skip_with_empty_check.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/skip_with_empty_check.php.inc new file mode 100644 index 00000000000..85d1f03673d --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamStringTypeFromSprintfUseRector/Fixture/skip_with_empty_check.php.inc @@ -0,0 +1,16 @@ +nodeTypeResolver->getType($messageArg->value); - $messageValue = $this->valueResolver->getValue($messageArg->value); if (! is_string($messageValue)) { continue; @@ -75,6 +75,11 @@ public function matchMask(ClassMethod|Function_ $functionLike, string $variableN continue; } + $type = $this->nodeTypeResolver->getType($arg->value); + if ($type instanceof MixedType && $type->getSubtractedType() instanceof UnionType) { + continue; + } + return true; } } From 2815193fbb8461dcb6c65ec1c3fdac14e45269db Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Oct 2025 15:18:40 +0700 Subject: [PATCH 2/2] us native --- .../NodeAnalyzer/VariableInSprintfMaskMatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php b/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php index 5f2814d606e..97af4db98f4 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php +++ b/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php @@ -75,7 +75,7 @@ public function matchMask(ClassMethod|Function_ $functionLike, string $variableN continue; } - $type = $this->nodeTypeResolver->getType($arg->value); + $type = $this->nodeTypeResolver->getNativeType($arg->value); if ($type instanceof MixedType && $type->getSubtractedType() instanceof UnionType) { continue; }