Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/PhpParser/PrettyPrinterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,10 @@ protected function p(
}

[$printFn, $skipToken, $findToken] = $this->modifierChangeMap[$key];
if ($skipToken === \T_NEW && $pos !== $startPos) {
// Anonymous class attributes were printed, so we are already past "new".
$skipToken = \T_WHITESPACE;
}
$skipWSPos = $this->origTokens->skipRight($pos, $skipToken);
$result .= $this->origTokens->getTokenCode($pos, $skipWSPos, $indentAdjustment);
$result .= $this->$printFn($subNode);
Expand Down
19 changes: 18 additions & 1 deletion test/code/formatPreservation/modifierChange.test
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,21 @@ class X {
protected function m() {}
/** A */
protected function m2() {}
}
}
-----
<?php
new #[A] class {};
new #[A] readonly class {};
new class {};
-----
$stmts[0]->expr->class->flags = Modifiers::READONLY;
$stmts[1]->expr->class->flags = 0;
$stmts[2]->expr->class->flags = Modifiers::READONLY;
$stmts[2]->expr->class->attrGroups[] = new Node\AttributeGroup([
new Node\Attribute(new Node\Name('B'), []),
]);
-----
<?php
new #[A] readonly class {};
new #[A] class {};
new #[B] readonly class {};
Loading