From 96e3e80f9a1bd8855b391c64b326b8151a9b9d54 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Oct 2025 16:42:22 +0700 Subject: [PATCH 1/6] [TypeDeclaration] Skip possibly unclear type on AddParamFromDimFetchKeyUseRector --- .../skip_mix_clear_and_unclear_type.php.inc | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc new file mode 100644 index 00000000000..bc45940d574 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc @@ -0,0 +1,20 @@ + 'Firstitem', + 'second' => 'Seconditem', + ]; + + return $items[$key]; + } +} From da44ee97ef0eabb1ab20ce032b4d51d9d69c7e6f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Oct 2025 16:43:55 +0700 Subject: [PATCH 2/6] [TypeDeclaration] Skip possibly unclear type on AddParamFromDimFetchKeyUseRector --- .../Fixture/skip_mix_clear_and_unclear_type.php.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc index bc45940d574..1d5868ec3a7 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc @@ -2,7 +2,7 @@ namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddParamFromDimFetchKeyUseRector\Fixture; -final class Fixture +final class SkipMixClearAndUnClearType { public function process($key, $unclearType) { From f7baeb1f04c8526df9e51db5ebc45ac44de3d88d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Oct 2025 16:45:15 +0700 Subject: [PATCH 3/6] true found early --- .../skip_mix_clear_and_unclear_type.php.inc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc index 1d5868ec3a7..5abf6729ffe 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc @@ -7,14 +7,14 @@ final class SkipMixClearAndUnClearType public function process($key, $unclearType) { if (rand(0, 1)) { - return $unclearType[$key]; - } + $items = [ + 'first' => 'Firstitem', + 'second' => 'Seconditem', + ]; - $items = [ - 'first' => 'Firstitem', - 'second' => 'Seconditem', - ]; + return $items[$key]; + } - return $items[$key]; + return $unclearType[$key]; } } From 0c96eac5371a40b92848664b4f08cd3e668adcac Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 13 Oct 2025 09:46:03 +0000 Subject: [PATCH 4/6] [ci-review] Rector Rectify --- .../NodeAnalyzer/VariableInSprintfMaskMatcher.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php b/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php index ee6e6d7c0e4..998e9109751 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php +++ b/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php @@ -31,9 +31,7 @@ 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'); - })); + $funcCalls = array_values(array_filter($funcCalls, fn(FuncCall $funcCall): bool => $this->nodeNameResolver->isName($funcCall->name, 'sprintf'))); if (count($funcCalls) !== 1) { return false; From 8b748011553dba79530898e3326f42b6bd60438d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Oct 2025 16:46:52 +0700 Subject: [PATCH 5/6] fix --- .../AddParamFromDimFetchKeyUseRector.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php index ad4e9e8b183..f7b5d79bea1 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php @@ -108,32 +108,34 @@ public function refactor(Node $node): ?Node continue; } + $paramTypeNode = null; + foreach ($dimFetches as $dimFetch) { $dimFetchType = $this->getType($dimFetch->var); if (! $dimFetchType instanceof ArrayType && ! $dimFetchType instanceof ConstantArrayType) { - continue; + continue 2; } if ($dimFetch->dim instanceof Variable) { $type = $this->nodeTypeResolver->getType($dimFetch->dim); if ($type instanceof UnionType) { - continue; + continue 2; } } + } - $paramTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode( - $dimFetchType->getKeyType(), - TypeKind::PARAM - ); - - if (! $paramTypeNode instanceof Node) { - continue; - } + $paramTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode( + $dimFetchType->getKeyType(), + TypeKind::PARAM + ); - $param->type = $paramTypeNode; - $hasChanged = true; + if (! $paramTypeNode instanceof Node) { + continue; } + + $param->type = $paramTypeNode; + $hasChanged = true; } } From fc999aeffe73d4f6afae7bdffa808255789fb2c0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 13 Oct 2025 16:48:49 +0700 Subject: [PATCH 6/6] fix --- .../Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php index f7b5d79bea1..4ebd95ccfe9 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php @@ -108,8 +108,6 @@ public function refactor(Node $node): ?Node continue; } - $paramTypeNode = null; - foreach ($dimFetches as $dimFetch) { $dimFetchType = $this->getType($dimFetch->var);