From 7e40a11ee89766c390212b34b0ad7237c55e8d72 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 4 Oct 2025 23:42:16 +0700 Subject: [PATCH 1/4] [TypeDeclaration] Skip parent __call() exists on KnownMagicClassMethodTypeRector --- .../Fixture/skip_exists_in_parent.php.inc | 12 ++++++++++++ .../Source/ParentClassWithCall.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassWithCall.php diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc new file mode 100644 index 00000000000..7b428a38ff9 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassWithCall.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassWithCall.php new file mode 100644 index 00000000000..3faf6bfef57 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassWithCall.php @@ -0,0 +1,12 @@ + Date: Sat, 4 Oct 2025 23:45:35 +0700 Subject: [PATCH 2/4] fix --- .../KnownMagicClassMethodTypeRector.php | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php index d8c4ebfd5f9..7917e871b23 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Stmt\Class_; use Rector\Rector\AbstractRector; use Rector\ValueObject\MethodName; +use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -20,6 +21,10 @@ */ final class KnownMagicClassMethodTypeRector extends AbstractRector { + public function __construct( + private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard + ){ + } public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -68,18 +73,24 @@ public function refactor(Node $node): ?Node continue; } - if ($this->isName($classMethod, MethodName::CALL)) { - $firstParam = $classMethod->getParams()[0]; - if (! $firstParam->type instanceof Node) { - $firstParam->type = new Identifier('string'); - $hasChanged = true; - } + if (! $this->isName($classMethod, MethodName::CALL)) { + continue; + } + + if ($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod)) { + return null; + } + + $firstParam = $classMethod->getParams()[0]; + if (! $firstParam->type instanceof Node) { + $firstParam->type = new Identifier('string'); + $hasChanged = true; + } - $secondParam = $classMethod->getParams()[1]; - if (! $secondParam->type instanceof Node) { - $secondParam->type = new Name('array'); - $hasChanged = true; - } + $secondParam = $classMethod->getParams()[1]; + if (! $secondParam->type instanceof Node) { + $secondParam->type = new Name('array'); + $hasChanged = true; } } From aef2e8863edb1d83612cfda7eb97b54d804ea2a1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 4 Oct 2025 23:46:05 +0700 Subject: [PATCH 3/4] fix --- .../Fixture/skip_exists_in_parent.php.inc | 2 -- .../Source/ParentClassWithCall.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc index 7b428a38ff9..981e8a96ca5 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc @@ -8,5 +8,3 @@ final class SkipExistsInParent extends ParentClass { } } - -?> \ No newline at end of file diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassWithCall.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassWithCall.php index 3faf6bfef57..8801dbcefad 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassWithCall.php +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassWithCall.php @@ -9,4 +9,4 @@ abstract class ParentClassWithCall public function __call($method, $args) { } -} \ No newline at end of file +} From f4b1008957d537e273caa14f052ccf57ef3fb346 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 4 Oct 2025 23:46:24 +0700 Subject: [PATCH 4/4] fix --- .../Fixture/skip_exists_in_parent.php.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc index 981e8a96ca5..890a68ce4ad 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/skip_exists_in_parent.php.inc @@ -2,7 +2,9 @@ namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\KnownMagicClassMethodTypeRector\Fixture; -final class SkipExistsInParent extends ParentClass +use Rector\Tests\TypeDeclaration\Rector\ClassMethod\KnownMagicClassMethodTypeRector\Source\ParentClassWithCall; + +final class SkipExistsInParent extends ParentClassWithCall { public function __call($method, $args) {