From 87aa45b08625267bffe2e6f883a6b5b6ac9851e3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Oct 2025 08:36:36 +0700 Subject: [PATCH 1/2] [TypeDeclaration] Skip has parent method on AddParamFromDimFetchKeyUseRector --- .../Fixture/skip_has_parent_method.php.inc | 18 ++++++++++++++++++ .../Source/SomeParentMethod.php | 12 ++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_has_parent_method.php.inc create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Source/SomeParentMethod.php diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_has_parent_method.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_has_parent_method.php.inc new file mode 100644 index 00000000000..42025cdda15 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_has_parent_method.php.inc @@ -0,0 +1,18 @@ + 'Firstitem', + 'second' => 'Seconditem', + ]; + + return $items[$key]; + } +} \ No newline at end of file diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Source/SomeParentMethod.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Source/SomeParentMethod.php new file mode 100644 index 00000000000..a611d6df148 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Source/SomeParentMethod.php @@ -0,0 +1,12 @@ + Date: Sun, 5 Oct 2025 08:38:37 +0700 Subject: [PATCH 2/2] fix --- .../Fixture/skip_has_parent_method.php.inc | 2 +- .../ClassMethod/AddParamFromDimFetchKeyUseRector.php | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_has_parent_method.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_has_parent_method.php.inc index 42025cdda15..440c7b5d479 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_has_parent_method.php.inc +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_has_parent_method.php.inc @@ -15,4 +15,4 @@ final class SkipHasParentMethod extends SomeParentMethod return $items[$key]; } -} \ No newline at end of file +} diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php index ee74dc5ae60..f5890898da5 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php @@ -12,6 +12,7 @@ use Rector\Rector\AbstractRector; use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclarationDocblocks\NodeFinder\ArrayDimFetchFinder; +use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -22,7 +23,8 @@ final class AddParamFromDimFetchKeyUseRector extends AbstractRector { public function __construct( private readonly ArrayDimFetchFinder $arrayDimFetchFinder, - private readonly StaticTypeMapper $staticTypeMapper + private readonly StaticTypeMapper $staticTypeMapper, + private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard ) { } @@ -87,6 +89,10 @@ public function refactor(Node $node): ?Node continue; } + if ($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod)) { + continue; + } + foreach ($classMethod->getParams() as $param) { if ($param->type instanceof Node) { continue;