Final Class Yiisoft\CodeStyle\Rector\Rules\RemoveOverrideAttributeRector
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Symplify\ |
Public Methods
Method Details
| public array getNodeTypes ( ) |
public function getNodeTypes(): array
{
return [ClassMethod::class];
}
| public \ |
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Remove #[Override] attribute from methods',
[
new CodeSample(
<<<'CODE_SAMPLE'
class Child extends Parent
{
#[Override]
public function foo(): void {}
}
CODE_SAMPLE,
<<<'CODE_SAMPLE'
class Child extends Parent
{
public function foo(): void {}
}
CODE_SAMPLE,
),
],
);
}
| public ?\ | ||
| $node | \ |
|
public function refactor(Node $node): ?Node
{
if (!$node instanceof ClassMethod) {
return null;
}
$changed = false;
foreach ($node->attrGroups as $groupKey => $attrGroup) {
foreach ($attrGroup->attrs as $attrKey => $attr) {
if ($this->getName($attr->name) === 'Override') {
unset($attrGroup->attrs[$attrKey]);
$changed = true;
break;
}
}
if ($attrGroup->attrs === []) {
unset($node->attrGroups[$groupKey]);
}
}
if (!$changed) {
return null;
}
$node->attrGroups = array_values($node->attrGroups);
return $node;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.