Skip to content

Commit e77a89b

Browse files
committed
handle ctor only
1 parent eb93cbb commit e77a89b

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Fixture;
4+
5+
#[\Attribute()]
6+
final class NonConstructorAttribute
7+
{
8+
/**
9+
* @param class-string $className
10+
*/
11+
public function run(string $className)
12+
{
13+
}
14+
}
15+
16+
?>
17+
-----
18+
<?php
19+
20+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Fixture;
21+
22+
#[\Attribute()]
23+
final class NonConstructorAttribute
24+
{
25+
}
26+
27+
?>

rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ private function shouldSkipClassMethod(Class_ $class, ClassMethod $classMethod):
171171
return false;
172172
}
173173

174-
// skip constructor in attributes as might be a marker parameter
175-
return $classReflection->isAttributeClass() && $classMethod->getDocComment() instanceof Doc;
174+
return $this->isAttributeMarkerConstructor($classMethod, $classReflection);
176175
}
177176

178177
private function hasDeprecatedAnnotation(ClassMethod $classMethod): bool
@@ -184,4 +183,20 @@ private function hasDeprecatedAnnotation(ClassMethod $classMethod): bool
184183

185184
return $phpDocInfo->hasByType(DeprecatedTagValueNode::class);
186185
}
186+
187+
/**
188+
* Skip constructor in attributes as might be a marker parameter
189+
*/
190+
private function isAttributeMarkerConstructor(ClassMethod $classMethod, ClassReflection $classReflection): bool
191+
{
192+
if (! $this->isName($classMethod, MethodName::CONSTRUCT)) {
193+
return false;
194+
}
195+
196+
if (! $classReflection->isAttributeClass()) {
197+
return false;
198+
}
199+
200+
return $classMethod->getDocComment() instanceof Doc;
201+
}
187202
}

0 commit comments

Comments
 (0)