From 7366fc545dd62154fd2c3a8fc78875676b8ad00a Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 19 Nov 2025 11:32:34 +0000 Subject: [PATCH 1/2] 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. --- ...th_mixed_attribute_and_annotations.php.inc | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Behat/with_mixed_attribute_and_annotations.php.inc diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Behat/with_mixed_attribute_and_annotations.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Behat/with_mixed_attribute_and_annotations.php.inc new file mode 100644 index 00000000000..e1f701a0279 --- /dev/null +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/Behat/with_mixed_attribute_and_annotations.php.inc @@ -0,0 +1,43 @@ + +----- + From 59b27cf06f3023fcf0d8a89786ca46f2454a25ec Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 19 Nov 2025 11:56:13 +0000 Subject: [PATCH 2/2] 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. --- rules/Php80/Rector/Class_/AttributeValueResolver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rules/Php80/Rector/Class_/AttributeValueResolver.php b/rules/Php80/Rector/Class_/AttributeValueResolver.php index df26cb4b8b0..077d1b45e9b 100644 --- a/rules/Php80/Rector/Class_/AttributeValueResolver.php +++ b/rules/Php80/Rector/Class_/AttributeValueResolver.php @@ -32,7 +32,9 @@ public function resolve( if ($phpDocTagNode->value instanceof DoctrineAnnotationTagValueNode) { $originalContent = (string) $phpDocTagNode->value->getOriginalContent(); - if ($docValue !== '') { + if ($docValue === '') { + $docValue = $originalContent; + } else { $attributeComment = ltrim($originalContent, $docValue); if ($attributeComment !== '') { $docValue .= "\n" . $attributeComment;