Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
}
Loading