Skip to content

Commit

Permalink
[Downgradephp80] Better add new line handling with insert \n prefix f…
Browse files Browse the repository at this point in the history
…or same line attribute
  • Loading branch information
samsonasik committed Nov 25, 2024
1 parent 4201862 commit 3116c2b
Showing 1 changed file with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,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;
Expand Down Expand Up @@ -161,12 +160,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;
}
Expand Down

0 comments on commit 3116c2b

Please sign in to comment.