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 1c27344 commit 7e7f1e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7e7f1e2

Please sign in to comment.