From 832e458817d9d7bff06ba321aea44a9ce3bb7819 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 15 Dec 2024 03:27:26 +0700 Subject: [PATCH] [Php80] Handle value as argument with keep description as comment on AttributeValueResolver (#6589) * [Php80] Handle behat @When with values as argument and description as comment * debugging * handle comment as value * [Php80] Handle value as argument with keep description as comment on AttributeValueResolver * new lines * new lines * deetail --- ..._value_as_argument_and_description.php.inc | 44 +++++++++++++++++++ .../Rector/Class_/AttributeValueResolver.php | 20 +++++++-- 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/with_value_as_argument_and_description.php.inc diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/with_value_as_argument_and_description.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/with_value_as_argument_and_description.php.inc new file mode 100644 index 0000000000..608565a3b2 --- /dev/null +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/with_value_as_argument_and_description.php.inc @@ -0,0 +1,44 @@ + +----- + diff --git a/rules/Php80/Rector/Class_/AttributeValueResolver.php b/rules/Php80/Rector/Class_/AttributeValueResolver.php index 5076d7c3fe..b5e87b229e 100644 --- a/rules/Php80/Rector/Class_/AttributeValueResolver.php +++ b/rules/Php80/Rector/Class_/AttributeValueResolver.php @@ -7,6 +7,7 @@ use Nette\Utils\Strings; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Php80\ValueObject\AnnotationToAttribute; use Rector\Php80\ValueObject\AttributeValueAndDocComment; use Rector\Util\NewLineSplitter; @@ -27,10 +28,23 @@ public function resolve( return null; } + $docValue = (string) $phpDocTagNode->value; + if ($phpDocTagNode->value instanceof DoctrineAnnotationTagValueNode) { - $docValue = (string) $phpDocTagNode->value->getOriginalContent(); - } else { - $docValue = (string) $phpDocTagNode->value; + $originalContent = (string) $phpDocTagNode->value->getOriginalContent(); + + if ($docValue === '') { + $attributeComment = (string) $phpDocTagNode->value->getAttribute(AttributeKey::ATTRIBUTE_COMMENT); + + if ($originalContent === $attributeComment) { + $docValue = $originalContent; + } + } else { + $attributeComment = ltrim($originalContent, $docValue); + if ($attributeComment !== '') { + $docValue .= "\n" . $attributeComment; + } + } } $docComment = '';