diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php index 9ccbb257b14..fc832fb362a 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php @@ -10,7 +10,6 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\PhpDocParser\Ast\PhpDoc\DeprecatedTagValueNode; -use PHPStan\Reflection\ClassReflection; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Configuration\Parameter\FeatureFlags; @@ -176,12 +175,7 @@ private function shouldSkipClassMethod(Class_ $class, ClassMethod $classMethod): return true; } - $classReflection = $scope->getClassReflection(); - if (! $classReflection instanceof ClassReflection) { - return false; - } - - return $this->isAttributeMarkerConstructor($classMethod, $classReflection); + return $this->isAttributeMarkerConstructor($classMethod, $class); } private function hasDeprecatedAnnotation(ClassMethod $classMethod): bool @@ -197,16 +191,29 @@ private function hasDeprecatedAnnotation(ClassMethod $classMethod): bool /** * Skip constructor in attributes as might be a marker parameter */ - private function isAttributeMarkerConstructor(ClassMethod $classMethod, ClassReflection $classReflection): bool + private function isAttributeMarkerConstructor(ClassMethod $classMethod, Class_ $class): bool { if (! $this->isName($classMethod, MethodName::CONSTRUCT)) { return false; } - if (! $classReflection->isAttributeClass()) { + if (! $this->isAttributeClass($class)) { return false; } return $classMethod->getDocComment() instanceof Doc; } + + private function isAttributeClass(Class_ $class): bool + { + foreach ($class->attrGroups as $attrGroup) { + foreach ($attrGroup->attrs as $attr) { + if ($this->isName($attr->name, 'Attribute')) { + return true; + } + } + } + + return false; + } }