|
10 | 10 | use PhpParser\Node\Stmt\Class_; |
11 | 11 | use Rector\Rector\AbstractRector; |
12 | 12 | use Rector\ValueObject\MethodName; |
| 13 | +use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; |
13 | 14 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
14 | 15 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
15 | 16 |
|
|
20 | 21 | */ |
21 | 22 | final class KnownMagicClassMethodTypeRector extends AbstractRector |
22 | 23 | { |
| 24 | + public function __construct( |
| 25 | + private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard |
| 26 | + ){ |
| 27 | + } |
23 | 28 | public function getRuleDefinition(): RuleDefinition |
24 | 29 | { |
25 | 30 | return new RuleDefinition( |
@@ -68,18 +73,24 @@ public function refactor(Node $node): ?Node |
68 | 73 | continue; |
69 | 74 | } |
70 | 75 |
|
71 | | - if ($this->isName($classMethod, MethodName::CALL)) { |
72 | | - $firstParam = $classMethod->getParams()[0]; |
73 | | - if (! $firstParam->type instanceof Node) { |
74 | | - $firstParam->type = new Identifier('string'); |
75 | | - $hasChanged = true; |
76 | | - } |
| 76 | + if (! $this->isName($classMethod, MethodName::CALL)) { |
| 77 | + continue; |
| 78 | + } |
| 79 | + |
| 80 | + if ($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod)) { |
| 81 | + return null; |
| 82 | + } |
| 83 | + |
| 84 | + $firstParam = $classMethod->getParams()[0]; |
| 85 | + if (! $firstParam->type instanceof Node) { |
| 86 | + $firstParam->type = new Identifier('string'); |
| 87 | + $hasChanged = true; |
| 88 | + } |
77 | 89 |
|
78 | | - $secondParam = $classMethod->getParams()[1]; |
79 | | - if (! $secondParam->type instanceof Node) { |
80 | | - $secondParam->type = new Name('array'); |
81 | | - $hasChanged = true; |
82 | | - } |
| 90 | + $secondParam = $classMethod->getParams()[1]; |
| 91 | + if (! $secondParam->type instanceof Node) { |
| 92 | + $secondParam->type = new Name('array'); |
| 93 | + $hasChanged = true; |
83 | 94 | } |
84 | 95 | } |
85 | 96 |
|
|
0 commit comments