From eb93cbb8ab94cb967054baa847cf799ff0b56b86 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 7 Jan 2026 13:07:30 +0100 Subject: [PATCH 1/2] skip marker attribute in RemoveEmptyClassMethodRector --- .../Fixture/skip_attribute_marker.php.inc | 14 ++++++++++++++ .../ClassMethod/RemoveEmptyClassMethodRector.php | 14 +++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/skip_attribute_marker.php.inc diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/skip_attribute_marker.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/skip_attribute_marker.php.inc new file mode 100644 index 00000000000..393e9a6ab73 --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/skip_attribute_marker.php.inc @@ -0,0 +1,14 @@ +isPublic(); } - return $this->isName($classMethod, MethodName::INVOKE); + if ($this->isName($classMethod, MethodName::INVOKE)) { + return true; + } + + $classReflection = $scope->getClassReflection(); + if (! $classReflection instanceof ClassReflection) { + return false; + } + + // skip constructor in attributes as might be a marker parameter + return $classReflection->isAttributeClass() && $classMethod->getDocComment() instanceof Doc; } private function hasDeprecatedAnnotation(ClassMethod $classMethod): bool From e77a89b139beb2b9475262d889b48d24d14cd5fc Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 7 Jan 2026 13:16:42 +0100 Subject: [PATCH 2/2] handle ctor only --- .../Fixture/non_constructor_attribute.php.inc | 27 +++++++++++++++++++ .../RemoveEmptyClassMethodRector.php | 19 +++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/non_constructor_attribute.php.inc diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/non_constructor_attribute.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/non_constructor_attribute.php.inc new file mode 100644 index 00000000000..a49416fede9 --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/non_constructor_attribute.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php index a64221b3595..6557fd579c4 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php @@ -171,8 +171,7 @@ private function shouldSkipClassMethod(Class_ $class, ClassMethod $classMethod): return false; } - // skip constructor in attributes as might be a marker parameter - return $classReflection->isAttributeClass() && $classMethod->getDocComment() instanceof Doc; + return $this->isAttributeMarkerConstructor($classMethod, $classReflection); } private function hasDeprecatedAnnotation(ClassMethod $classMethod): bool @@ -184,4 +183,20 @@ private function hasDeprecatedAnnotation(ClassMethod $classMethod): bool return $phpDocInfo->hasByType(DeprecatedTagValueNode::class); } + + /** + * Skip constructor in attributes as might be a marker parameter + */ + private function isAttributeMarkerConstructor(ClassMethod $classMethod, ClassReflection $classReflection): bool + { + if (! $this->isName($classMethod, MethodName::CONSTRUCT)) { + return false; + } + + if (! $classReflection->isAttributeClass()) { + return false; + } + + return $classMethod->getDocComment() instanceof Doc; + } }