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-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; + } + + return $this->isAttributeMarkerConstructor($classMethod, $classReflection); } private function hasDeprecatedAnnotation(ClassMethod $classMethod): bool @@ -172,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; + } }