From d72cb14d9f8edd6a0cb0e58f2a3f55398da3dabb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Oct 2025 01:02:51 +0700 Subject: [PATCH 1/4] [TypeDeclaration] Handle with other method from parent on KnownMagicClassMethodTypeRector --- .../with_other_method_from_parent.php.inc | 37 +++++++++++++++++++ .../Source/ParentClassOtherMethod.php | 10 +++++ 2 files changed, 47 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/with_other_method_from_parent.php.inc create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassOtherMethod.php diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/with_other_method_from_parent.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/with_other_method_from_parent.php.inc new file mode 100644 index 00000000000..6918d38af47 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/with_other_method_from_parent.php.inc @@ -0,0 +1,37 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassOtherMethod.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassOtherMethod.php new file mode 100644 index 00000000000..1bd7bc18e19 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source/ParentClassOtherMethod.php @@ -0,0 +1,10 @@ + Date: Sun, 5 Oct 2025 01:04:54 +0700 Subject: [PATCH 2/4] Fix --- composer.json | 3 ++- .../Rector/ClassMethod/KnownMagicClassMethodTypeRector.php | 2 +- src/VendorLocker/ParentClassMethodTypeOverrideGuard.php | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 032bceb95a7..3694a42b17b 100644 --- a/composer.json +++ b/composer.json @@ -90,7 +90,8 @@ "classmap": [ "stubs", "rules-tests/CodingStyle/Rector/Namespace_/ImportFullyQualifiedNamesRector/Source", - "rules-tests/Renaming/Rector/Name/RenameClassRector/Source" + "rules-tests/Renaming/Rector/Name/RenameClassRector/Source", + "rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Source" ], "files": [ "tests/debug_functions.php", diff --git a/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php index 5121f11721c..7be3745cecc 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php @@ -80,7 +80,7 @@ public function refactor(Node $node): ?Node } if ($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod)) { - return null; + continue; } if ($this->isNames($classMethod, [MethodName::CALL, MethodName::CALL_STATIC])) { diff --git a/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php b/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php index 545ec182962..6d83fff7311 100644 --- a/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php +++ b/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php @@ -34,6 +34,7 @@ public function hasParentClassMethod(ClassMethod|MethodReflection $classMethod): return $parentClassMethod instanceof MethodReflection; } catch (UnresolvableClassException) { + dump('here'); // we don't know all involved parents, // marking as parent exists which usually means the method is guarded against overrides. return true; From 3e39b7d1790ea31843695d7f8d5b20337df2d85b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Oct 2025 01:07:55 +0700 Subject: [PATCH 3/4] fix --- src/VendorLocker/ParentClassMethodTypeOverrideGuard.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php b/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php index 6d83fff7311..545ec182962 100644 --- a/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php +++ b/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php @@ -34,7 +34,6 @@ public function hasParentClassMethod(ClassMethod|MethodReflection $classMethod): return $parentClassMethod instanceof MethodReflection; } catch (UnresolvableClassException) { - dump('here'); // we don't know all involved parents, // marking as parent exists which usually means the method is guarded against overrides. return true; From b71ed979005aaa1b797039c4d12d89ef456d6624 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Oct 2025 01:08:06 +0700 Subject: [PATCH 4/4] fix --- .../Fixture/with_other_method_from_parent.php.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/with_other_method_from_parent.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/with_other_method_from_parent.php.inc index 6918d38af47..565999ee96b 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/with_other_method_from_parent.php.inc +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/with_other_method_from_parent.php.inc @@ -34,4 +34,4 @@ final class WithOtherMethodFromParent extends ParentClassWithOtherMethod } } -?> \ No newline at end of file +?>