Skip to content
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

feat: add the option to use the annotation value as an argument to the attribute #6468

Conversation

carlos-granados
Copy link
Contributor

@carlos-granados carlos-granados commented Nov 21, 2024

Currently if you have an annotation like the ones Behat uses:

    /**
     * @Given the user does not exist in the database
     */

When you use the AnnotationToAttributeRector rule configured like this:

    ->withConfiguredRule(AnnotationToAttributeRector::class, [
        new AnnotationToAttribute('Given', Given::class),
    ])

The value of the annotation ("the user does not exist in the database") is discarded and the end result is:

#[Given]

This PR adds a new useValueAsAttributeArgument option to the AnnotationToAttribute class. If this option is set to true, the value of the annotation will be used as an argument for the attribute, resulting in the correct result of:

#[Given('the user does not exist in the database')]

This option only applies to "generic" annotations. If Rector considers an annotation to be a "doctrine" annotation (for example if the annotation has parameters) then this won't apply

@TomasVotruba
Copy link
Member

Thank you 😊

@TomasVotruba TomasVotruba merged commit 1ec42bc into rectorphp:main Nov 24, 2024
36 checks passed
@TomasVotruba
Copy link
Member

@carlos-granados I thought this includes the Behat tests as well, only when I tried to run it :D

Could you add behat set as well and include it in ->withAttributes() method?

@carlos-granados carlos-granados deleted the use-annotation-value-as-attribute-argument branch November 25, 2024 14:44
@carlos-granados
Copy link
Contributor Author

@TomasVotruba I created a PR for this, please let me know if it is ok #6510

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.

3 participants