Commit b31f801
authored
[Php80] Handle mix still annotation and already attribute on AnnotationToAttributeRector (#7639)
* test: Prove bug in AnnotationToAttributeRector with mixed content
If a file already contains a mix of annotations and attributes, the
current AnnotationToAttributeRector implementation drops the annotation
value when generating the new Attribute tag.
This could happen, for example, with a Behat context in a legacy project
that has a mix of old and new step definitions.
* fix: AttributeValueResolver should not drop values of annotations
If the file being parsed has already imported a class matching the name
of the annotation tag, then the annotation tag will have been parsed
as a DoctrineAnnotationTagValueNode.
For some tags - e.g. Behat steps - the `$phpDocTagNode->value` will
cast to an empty string (because the annotation text does not actually
contain valid Doctrine annotation values). In this case, the actual
annotation value needs to be retrieved from
`$phpDocTagNode->value->getOriginalContent()`.
This was causing AnnotationToAttributeRector to drop the attribute
values when converting from annotations to attributes in a file that
already contained some attributes.
This was previously implemented, but was reverted more recently as part
of dropping support for comments on these nodes.1 parent 9e7f77d commit b31f801
File tree
2 files changed
+46
-1
lines changed- rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Behat
- rules/Php80/Rector/Class_
2 files changed
+46
-1
lines changedLines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
0 commit comments