From 3db9174b18437ec92d35d2e6abcd9aeb55f2f2ed Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 20 Oct 2025 16:44:42 +0700 Subject: [PATCH 1/2] [TypeDeclaration] Skip possibly null on AddParamFromDimFetchKeyUseRector --- .../Fixture/skip_possibly_null.php.inc | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_possibly_null.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_possibly_null.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_possibly_null.php.inc new file mode 100644 index 00000000000..41193f6e54a --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_possibly_null.php.inc @@ -0,0 +1,21 @@ + 'Firstitem', + 111 => 'Seconditem', + 'second' => 'Seconditem', + ]; + + return $items[$key]; + } +} From aecc0f51cbba1c42177237f5113aa8ce728a4f42 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 20 Oct 2025 16:46:26 +0700 Subject: [PATCH 2/2] fix --- .../ClassMethod/AddParamFromDimFetchKeyUseRector.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php index cb7687e482a..0d8848691a4 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php @@ -13,6 +13,7 @@ use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; use Rector\Rector\AbstractRector; use Rector\StaticTypeMapper\StaticTypeMapper; +use Rector\TypeDeclaration\Guard\ParamTypeAddGuard; use Rector\TypeDeclarationDocblocks\NodeFinder\ArrayDimFetchFinder; use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -26,7 +27,8 @@ final class AddParamFromDimFetchKeyUseRector extends AbstractRector public function __construct( private readonly ArrayDimFetchFinder $arrayDimFetchFinder, private readonly StaticTypeMapper $staticTypeMapper, - private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard + private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, + private readonly ParamTypeAddGuard $paramTypeAddGuard ) { } @@ -107,6 +109,10 @@ public function refactor(Node $node): ?Node continue; } + if (! $this->paramTypeAddGuard->isLegal($param, $classMethod)) { + continue; + } + foreach ($dimFetches as $dimFetch) { $dimFetchType = $this->getType($dimFetch->var);