Skip to content

Commit

Permalink
[BUGFIX] Ensure proper reprint with attributes for finalized classes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cngJo committed Jul 23, 2023
1 parent a7cd7ed commit 50a5bb4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
@@ -0,0 +1,21 @@
<?php

namespace Rector\Tests\Php82\Rector\Class_\ReadOnlyClassRector\Fixture;

#[SomeAttribute]
class ClassWithAttribute
{
}

?>
-----
<?php

namespace Rector\Tests\Php82\Rector\Class_\ReadOnlyClassRector\Fixture;

#[SomeAttribute]
final class ClassWithAttribute
{
}

?>
Expand Up @@ -12,6 +12,7 @@
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -100,6 +101,11 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->attrGroups !== []) {
// improve reprint with correct newline
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}

$this->visibilityManipulator->makeFinal($node);

return $node;
Expand Down

0 comments on commit 50a5bb4

Please sign in to comment.