Skip to content

Commit 3116c2b

Browse files
committed
[Downgradephp80] Better add new line handling with insert \n prefix for same line attribute
1 parent 4201862 commit 3116c2b

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,9 @@ public function refactor(Node $node): ?Node
119119
(string) $oldTokens[$attrGroup->getEndTokenPos() + 1],
120120
"\n"
121121
)) {
122-
$print = $this->betterStandardPrinter->print($attrGroup);
123-
$attributesAsComments[] = new Comment($print);
124-
125-
unset($attrGroup->attrs[$key]);
122+
// add new line
123+
$oldTokens[$attrGroup->getEndTokenPos() + 1]->text = "\n" . $oldTokens[$attrGroup->getEndTokenPos() + 1]->text;
124+
$this->isDowngraded = true;
126125
}
127126

128127
continue;
@@ -161,12 +160,6 @@ public function refactor(Node $node): ?Node
161160
// cleanup empty attr groups
162161
$this->cleanupEmptyAttrGroups($node);
163162

164-
if ($attributesAsComments !== []) {
165-
$this->isDowngraded = true;
166-
$currentComments = $node->getAttribute(AttributeKey::COMMENTS) ?? [];
167-
$node->setAttribute(AttributeKey::COMMENTS, array_merge($currentComments, $attributesAsComments));
168-
}
169-
170163
if (! $this->isDowngraded) {
171164
return null;
172165
}

0 commit comments

Comments
 (0)