-
-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Php80] Handle nested attribute with constant on AnnotationAttributeRector #1661
Conversation
Thanks 👍 Could you extract it to a new file? Each fixture should be as minimal as possible, as this annotation parsing deals with tokens and it's very detailed work. The smaller scope the better. |
@TomasVotruba done, but fixing this is definitely out of my league 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomasVotruba I reworked the example (it was wrong) and I attempted to fix the parsing. This is now ready for review.
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation; | ||
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\ConstantReference; | ||
|
||
#[GenericAnnotation(some: [ConstantReference::FIRST_NAME => ['foo' => ['bar' => ['baz']]], 0 => ConstantReference::LAST_NAME])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to obtain this:
#[GenericAnnotation(some: [ConstantReference::FIRST_NAME => ['foo' => ['bar' => ['baz']]], 0 => ConstantReference::LAST_NAME])] | |
#[GenericAnnotation(some: [ConstantReference::FIRST_NAME => ['foo' => ['bar' => ['baz']]], ConstantReference::LAST_NAME])] |
... but it seems basically impossible, since there's no way to say to PHP "this element has no key", it does in fact have one, just an autogenerated-due-to-append one.
@Jean85 as you provided a fix as well, could you update PR title? something like: [Php80] Handle nested attribute with constant on AnnotationAttributeRector ? |
Done, thanks for the suggestion, I'm on mobile and I just copy pasted it 😂 |
$tokenIterator->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL); | ||
|
||
if ($tokenIterator->isCurrentTokenTypes([Lexer::TOKEN_CLOSE_CURLY_BRACKET, Lexer::TOKEN_COMMA])) { | ||
// it's a value, not a key | ||
return [null, $key]; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I often struggle with the right tokens to consume. This is amazing work 👍 Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! The test suite was very comprehensive, and contributing was really easy! I struggled a little with the parsing too, but reviewing the fixture put me on the right track.
Thank you 👏 |
This is a follow-up as suggested in rectorphp/rector#6928 (comment), follow up of #1659.