Incorrect behavior of AnnotationToAttributeRector
Bug Report
| Subject | Details |
|---|---|
| Rector version | last dev-main |
| Installed as | composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.org/demo/4aed0527-1eb1-420d-8af3-81de2423063a
<?php
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @Serializer\DiscriminatorMap(typeProperty = "type", mapping = {
* "FOO" : TestFoo::class,
* "BAR" : TestBar::class
* })
*/
interface TInterface
{
}
/**
* @Serializer\DiscriminatorMap(typeProperty = "type", mapping = {
* "FOO" : TestFoo::class,
* "BAR" : TestBar::class
* })
*/
class TestFoo implements TInterface {
}
Responsible rules
-
AnnotationToAttributeRector
Expected Behavior
Interfaces should also be supported by AnnotationToAttributeRector
@astronom could you provide a PR patch for it, you can do the following steps:
-
Add failing fixture at https://github.com/rectorphp/rector-src/tree/8615aa59fb9e0f650e529f8e08e02b8b3a7dd0ac/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture
-
Add class annotation to be transformed to configure_rule.php for sample https://github.com/rectorphp/rector-src/blob/8615aa59fb9e0f650e529f8e08e02b8b3a7dd0ac/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php
-
Run test:
vendor/bin/phpunit rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/AnnotationToAttributeRectorTest.php
- Make a patch, it should only add
\PhpParser\Node\Stmt\Interface_atgetNodeTypes()return data:
https://github.com/rectorphp/rector-src/blob/8615aa59fb9e0f650e529f8e08e02b8b3a7dd0ac/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php#L99
- Update param doc and maybe code related to it to include
\PhpParser\Node\Stmt\Interface_as well
https://github.com/rectorphp/rector-src/blob/8615aa59fb9e0f650e529f8e08e02b8b3a7dd0ac/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php#L113
Thank you.
@samsonasik ok, I will try