Repository navigation
Convert Doctrine annotations from phpdoc-parser nodes, remove StaticDoctrineAnnotationParser - #8881
Conversation
1293dde to
54899d0
Compare
…octrineAnnotationParser Amp-Thread-ID: https://ampcode.com/threads/T-01a17930-0285-73c5-a957-4325c77aa1b2
54899d0 to
1815799
Compare
|
This is ready. |
|
Thanks the updates 👍 Great to have these glitches resolve out of the box. I think we can leave the invalid docblock in Doctrine tags behind. Let's merge 🚀 |
|
MIght regres drupal rector a bit this, not 100% sure yet. We used part of this code to do annotation to attribute conversion for Drupal |
|
We still do annotation to attributes conversion as before. |
|
Yeah will investigate and post back if there work in rector. |
|
Well, seems this is not really an issue, but i did find a discrepancy between doctrines parser and rector. https://getrector.com/demo/0ffc42df-7754-41b2-969e-b8e30dde6c1e But it seems this might not be a rector issue but a phpstan issue ;x |
…8900) On Windows, Git checks out the test files with CRLF, so the heredoc input contains \r\n. Format-preserving printing correctly keeps those line endings, so the output is normalized before comparing with LF-only expectations. Amp-Thread-ID: https://ampcode.com/threads/T-01a1908f-48b6-7423-b4cd-641c531e141f
|
@bbrala how often the open parentheses on new line happen in projects? |
|
I only found one oublic drupal modules with this pattern. So I guess not that much. I dont know custom code of course. But its not wide spread |
|
@ondrejmirtes can parentheses in new line be supported, that would be great if it works out of the box |
|
It would need to be more greedy and do newlines. Might have performance implicatio s. Im not sure of the real life impact, but it would be more correct since that is how the doctrine parser works. |
|
as this changing code, correctness should more important than speed so it would be great if this not cause regression on allowed annotation syntax so would be great to have support out of the box. |
…rrayParser (#443) rectorphp/rector-src#8881 removed StaticDoctrineAnnotationParser\ArrayParser, so the rule failed to construct on Rector dev-main. The GenericTagValueNode branch only produced a correct attribute for an argument-less tag; convert that to an attribute without arguments and leave other unparsed tags alone.
And now a dessert 😉
phpdoc-parser already parses Doctrine annotations (since 1.22.0) to
DoctrineTagValueNode. Before,DoctrineAnnotationDecoratorprinted these nodes back to a string and parsed the string again withStaticDoctrineAnnotationParser,ArrayParserandPlainValueParser. Now the decorator converts the phpdoc-parser nodes directly toDoctrineAnnotationTagValueNode,CurlyListNode,ArrayItemNodeandStringNode. The public API does not change.Removed:
StaticDoctrineAnnotationParser,ArrayParser,PlainValueParser,NextTokenType, and the@\FQNtext and description splitting inDoctrineAnnotationDecorator.Changes in behaviour. Rector now uses the phpdoc-parser and Doctrine semantics:
*line prefixes in the docblock node, as in doctrine/annotations. When Rector converts it to an attribute, it removes the prefixes.{}list in a{}list is aCurlyListNode. Before, it was a PHP array.{1="Foo"}.ArrayItemNodenow prints integer keys. Before, a changed annotation lost them.null. Before, the key was0.@Foo('bar'),@Foo("key"="value"). phpdoc-parser givesInvalidTagValueNodefor them, and Rector does not change them. Fixtures are updated.Needs rectorphp/rector-doctrine#543 to be merged first.