Skip to content

Commit

Permalink
[CodingStyle] Remove parent attribute usage on RemoveFinalFromConstRe…
Browse files Browse the repository at this point in the history
…ctor (#3536)

* CodingStyle] Remove parent attribute usage on RemoveFinalFromConstRector

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Mar 29, 2023
1 parent 0d5169d commit 34ff324
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions rules/CodingStyle/Rector/ClassConst/RemoveFinalFromConstRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
Expand Down Expand Up @@ -53,22 +52,29 @@ final class SomeClass
*/
public function getNodeTypes(): array
{
return [ClassConst::class];
return [Class_::class];
}

/**
* @param ClassConst $node
* @param Class_ $node
*/
public function refactor(Node $node): ?Node
{
$parentClass = $this->betterNodeFinder->findParentType($node, Class_::class);

if (! $parentClass instanceof Class_) {
if (! $node->isFinal()) {
return null;
}

if ($parentClass->isFinal() && $node->isFinal()) {
$this->visibilityManipulator->removeFinal($node);
$hasChanged = false;
foreach ($node->getConstants() as $classConst) {
if (! $classConst->isFinal()) {
continue;
}

$this->visibilityManipulator->removeFinal($classConst);
$hasChanged = true;
}

if ($hasChanged) {
return $node;
}

Expand Down

0 comments on commit 34ff324

Please sign in to comment.