Skip to content

Commit

Permalink
cover slash newline in AnnotationToAttributeRector
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Dec 11, 2024
1 parent c48a7b0 commit 18c7c3b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rules/Php80/Rector/Class_/AnnotationToAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Php80\Rector\Class_;

use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr\ArrowFunction;
Expand Down Expand Up @@ -204,10 +205,20 @@ private function processGenericTags(PhpDocInfo $phpDocInfo): array
continue;
}

$docValue = null;
if ($annotationToAttribute->getUseValueAsAttributeArgument()) {
// special case for newline
$docValue = (string) $docNode->value;
if (str_contains($docValue, '\\')) {
$docValue = Strings::replace($docValue, "#\\\\\n#", '');
}
}

$attributeGroups[] = $this->phpAttributeGroupFactory->createFromSimpleTag(
$annotationToAttribute,
$annotationToAttribute->getUseValueAsAttributeArgument() ? (string) $docNode->value : null
$docValue
);

return PhpDocNodeTraverser::NODE_REMOVE;
}

Expand Down

0 comments on commit 18c7c3b

Please sign in to comment.