KEMBAR78
feat: add the option to use the annotation value as an argument to the attribute by carlos-granados · Pull Request #6468 · rectorphp/rector-src · GitHub
Skip to content

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