diff --git a/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php b/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php index f323951b..c20e2f00 100644 --- a/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php +++ b/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp80\Rector\Class_; -use PhpParser\Comment; use PhpParser\Node; use PhpParser\Node\Attribute; use PhpParser\Node\Param; @@ -20,8 +19,6 @@ use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\DowngradePhp80\ValueObject\DowngradeAttributeToAnnotation; use Rector\NodeFactory\DoctrineAnnotationFactory; -use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\PhpParser\Printer\BetterStandardPrinter; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -49,8 +46,7 @@ final class DowngradeAttributeToAnnotationRector extends AbstractRector implemen public function __construct( private readonly DoctrineAnnotationFactory $doctrineAnnotationFactory, private readonly DocBlockUpdater $docBlockUpdater, - private readonly PhpDocInfoFactory $phpDocInfoFactory, - private readonly BetterStandardPrinter $betterStandardPrinter + private readonly PhpDocInfoFactory $phpDocInfoFactory ) { } @@ -109,7 +105,6 @@ public function refactor(Node $node): ?Node $this->isDowngraded = false; $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); - $attributesAsComments = []; $oldTokens = $this->file->getOldTokens(); foreach ($node->attrGroups as $attrGroup) { @@ -119,10 +114,9 @@ public function refactor(Node $node): ?Node (string) $oldTokens[$attrGroup->getEndTokenPos() + 1], "\n" )) { - $print = $this->betterStandardPrinter->print($attrGroup); - $attributesAsComments[] = new Comment($print); - - unset($attrGroup->attrs[$key]); + // add new line + $oldTokens[$attrGroup->getEndTokenPos() + 1]->text = "\n" . $oldTokens[$attrGroup->getEndTokenPos() + 1]->text; + $this->isDowngraded = true; } continue; @@ -161,12 +155,6 @@ public function refactor(Node $node): ?Node // cleanup empty attr groups $this->cleanupEmptyAttrGroups($node); - if ($attributesAsComments !== []) { - $this->isDowngraded = true; - $currentComments = $node->getAttribute(AttributeKey::COMMENTS) ?? []; - $node->setAttribute(AttributeKey::COMMENTS, array_merge($currentComments, $attributesAsComments)); - } - if (! $this->isDowngraded) { return null; }