Skip to content

Printer: put back asterisks in multi-line texts and descriptions - #328

Merged
ondrejmirtes merged 1 commit into
phpstan:2.3.xfrom
ondrejmirtes:multiline-description-asterisks
Oct 26, 2026
Merged

ondrejmirtes merged 1 commit into
phpstan:2.3.xfrom
ondrejmirtes:multiline-description-asterisks

Conversation

@ondrejmirtes

@ondrejmirtes ondrejmirtes commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

The parser removes * at the start of each line of a text or description:

/**
 * First line
 * second line
 */

gives PhpDocTextNode('First line' . "\n" . 'second line'). The printer did not put the * back, so it printed a broken PHPDoc:

/**
 * First line
second line
 */

This occurred in print() and in printFormatPreserving() when a node with a multi-line text or description was printed again, e.g. after a change to a @param with a multi-line description.

Now the printer writes the line start after each newline. printFormatPreserving() uses the line start of the original PHPDoc, so the indentation stays the same:

    /**
     * Changed line
     * second line
     */

An empty line gets * without a space after it.

@ondrejmirtes
ondrejmirtes force-pushed the multiline-description-asterisks branch from 7589ee8 to e3fbd5d Compare October 26, 2026 18:14
The parser removes the asterisk at the start of each line of a text
or description. When the printer printed such a node, the lines after
the first had no asterisk.

The format-preserving printer now uses the line start of the original
PHPDoc, so the indentation stays the same.

Amp-Thread-ID: https://ampcode.com/threads/T-01a17930-0285-73c5-a957-4325c77aa1b2
@ondrejmirtes
ondrejmirtes force-pushed the multiline-description-asterisks branch from e3fbd5d to ec9542a Compare October 26, 2026 19:34
@ondrejmirtes
ondrejmirtes merged commit 5e32d48 into phpstan:2.3.x Oct 26, 2026
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant