From 7e7f1e2aadd03864e16ad550c8929a8f5164722f Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 11 Dec 2024 18:28:13 +0100 Subject: [PATCH] cover slash newline in AnnotationToAttributeRector --- .../Rector/Class_/AnnotationToAttributeRector.php | 13 ++++++++++++- .../PHPStan/Scope/PHPStanNodeScopeResolver.php | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php b/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php index 4f05d5474a..914bddc028 100644 --- a/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php +++ b/rules/Php80/Rector/Class_/AnnotationToAttributeRector.php @@ -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; @@ -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; } diff --git a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php index 4bac71c78b..522dda82e5 100644 --- a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php +++ b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php @@ -5,7 +5,6 @@ namespace Rector\NodeTypeResolver\PHPStan\Scope; use Error; -use PHPStan\Node\Printer\Printer; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\ArrayItem; @@ -84,6 +83,7 @@ use PHPStan\Analyser\MutatingScope; use PHPStan\Analyser\NodeScopeResolver; use PHPStan\Analyser\ScopeContext; +use PHPStan\Node\Printer\Printer; use PHPStan\Node\UnreachableStatementNode; use PHPStan\Node\VirtualNode; use PHPStan\Parser\ParserErrorsException;