Skip to content

Commit 03df849

Browse files
authored
[TypeDeclaration] Skip has parent method on AddParamFromDimFetchKeyUseRector (#7426)
* [TypeDeclaration] Skip has parent method on AddParamFromDimFetchKeyUseRector * fix
1 parent d52149d commit 03df849

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddParamFromDimFetchKeyUseRector\Fixture;
4+
5+
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddParamFromDimFetchKeyUseRector\Source\SomeParentMethod;
6+
7+
final class SkipHasParentMethod extends SomeParentMethod
8+
{
9+
public function process($key)
10+
{
11+
$items = [
12+
'first' => 'Firstitem',
13+
'second' => 'Seconditem',
14+
];
15+
16+
return $items[$key];
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddParamFromDimFetchKeyUseRector\Source;
6+
7+
class SomeParentMethod
8+
{
9+
public function process($key)
10+
{
11+
}
12+
}

rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Rector\Rector\AbstractRector;
1313
use Rector\StaticTypeMapper\StaticTypeMapper;
1414
use Rector\TypeDeclarationDocblocks\NodeFinder\ArrayDimFetchFinder;
15+
use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard;
1516
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1617
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1718

@@ -22,7 +23,8 @@ final class AddParamFromDimFetchKeyUseRector extends AbstractRector
2223
{
2324
public function __construct(
2425
private readonly ArrayDimFetchFinder $arrayDimFetchFinder,
25-
private readonly StaticTypeMapper $staticTypeMapper
26+
private readonly StaticTypeMapper $staticTypeMapper,
27+
private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard
2628
) {
2729
}
2830

@@ -87,6 +89,10 @@ public function refactor(Node $node): ?Node
8789
continue;
8890
}
8991

92+
if ($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod)) {
93+
continue;
94+
}
95+
9096
foreach ($classMethod->getParams() as $param) {
9197
if ($param->type instanceof Node) {
9298
continue;

0 commit comments

Comments
 (0)