Skip to content

Printer: keep Doctrine annotation name and missing parentheses - #327

Merged
ondrejmirtes merged 1 commit into
phpstan:2.3.xfrom
ondrejmirtes:doctrine-tag-format-preserving
Oct 26, 2026
Merged

ondrejmirtes merged 1 commit into
phpstan:2.3.xfrom
ondrejmirtes:doctrine-tag-format-preserving

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

This PR fixes 2 errors in Printer::printFormatPreserving() for Doctrine annotations.

  1. An annotation without arguments, e.g. @\Foo\Id, has no tokens. The printer reprinted the tag and added (), also when nothing changed:

    /** @\Foo\Id */  →  /** @\Foo\Id() */
    

    Now, if a sub-node has no tokens and prints the same as the original sub-node, the printer keeps it.

  2. The tokens of DoctrineTagValueNode do not contain the annotation name. The parent PhpDocTagNode prints the name. When the printer reprinted only the value, the name was printed twice:

    /** @Route("/path") some description */  →  /** @Route@Route("/path") other description */
    

    Now the printer prints the value without the name. If the original annotation had no parentheses and has no arguments, the printer does not add them.

Found when I examined how Rector can replace its own docblock printer with this printer.

A Doctrine annotation without arguments, e.g. @\Foo\Id, has no tokens.
The format-preserving printer reprinted the tag and added "()",
also when nothing changed.

The tokens of DoctrineTagValueNode do not contain the annotation name.
When the printer reprinted only the value, the name was printed twice,
e.g. @route@Route("/path") other description.

Amp-Thread-ID: https://ampcode.com/threads/T-01a17930-0285-73c5-a957-4325c77aa1b2
@ondrejmirtes
ondrejmirtes merged commit f26818e into phpstan:2.3.x Oct 26, 2026
60 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