Skip to content

Commit 4325c25

Browse files
committed
fix
1 parent 7e40a11 commit 4325c25

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpParser\Node\Stmt\Class_;
1111
use Rector\Rector\AbstractRector;
1212
use Rector\ValueObject\MethodName;
13+
use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard;
1314
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1415
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1516

@@ -20,6 +21,10 @@
2021
*/
2122
final class KnownMagicClassMethodTypeRector extends AbstractRector
2223
{
24+
public function __construct(
25+
private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard
26+
){
27+
}
2328
public function getRuleDefinition(): RuleDefinition
2429
{
2530
return new RuleDefinition(
@@ -68,18 +73,24 @@ public function refactor(Node $node): ?Node
6873
continue;
6974
}
7075

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+
}
7789

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;
8394
}
8495
}
8596

0 commit comments

Comments
 (0)