Skip to content

Commit efa3610

Browse files
committed
[Removing] Use explicit node types in RemoveAttributeRector
1 parent 2a86654 commit efa3610

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

rules/Removing/Rector/Attribute/RemoveAttributeRector.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66

77
use PhpParser\Node;
88
use PhpParser\Node\AttributeGroup;
9+
use PhpParser\Node\Expr\ArrowFunction;
10+
use PhpParser\Node\Expr\Closure;
911
use PhpParser\Node\Param;
12+
use PhpParser\Node\PropertyHook;
13+
use PhpParser\Node\Stmt\ClassConst;
14+
use PhpParser\Node\Stmt\ClassLike;
15+
use PhpParser\Node\Stmt\ClassMethod;
16+
use PhpParser\Node\Stmt\Const_;
17+
use PhpParser\Node\Stmt\EnumCase;
18+
use PhpParser\Node\Stmt\Function_;
1019
use PhpParser\Node\Stmt\Property;
1120
use Rector\Contract\Rector\ConfigurableRectorInterface;
1221
use Rector\Rector\AbstractRector;
@@ -53,25 +62,26 @@ class SomeClass
5362
*/
5463
public function getNodeTypes(): array
5564
{
56-
return [Node::class];
65+
return [
66+
ArrowFunction::class,
67+
ClassConst::class,
68+
ClassLike::class,
69+
ClassMethod::class,
70+
Closure::class,
71+
Const_::class,
72+
EnumCase::class,
73+
Function_::class,
74+
Param::class,
75+
Property::class,
76+
PropertyHook::class,
77+
];
5778
}
5879

80+
/**
81+
* @param ArrowFunction|ClassConst|ClassLike|ClassMethod|Closure|Const_|EnumCase|Function_|Param|Property|PropertyHook $node
82+
*/
5983
public function refactor(Node $node): ?Node
6084
{
61-
if (! in_array('attrGroups', $node->getSubNodeNames(), true)) {
62-
return null;
63-
}
64-
65-
if (! isset($node->attrGroups) || $node->attrGroups === null || $node->attrGroups === []) {
66-
return null;
67-
}
68-
69-
foreach ($node->attrGroups as $attrGroup) {
70-
if (! $attrGroup instanceof AttributeGroup) {
71-
return null;
72-
}
73-
}
74-
7585
$nodeTypes = [$node::class];
7686
if ($node instanceof Param && $node->isPromoted()) {
7787
// An attribute removed from a parameter or property must be removed from a promoted property because an

0 commit comments

Comments
 (0)