Skip to content

Commit b0ff848

Browse files
committed
remove attribute comments support as comments require standalone line before any doctrine annotation
1 parent 5cb3b9e commit b0ff848

7 files changed

Lines changed: 6 additions & 94 deletions

File tree

build/target-repository/docs/rector_rules_overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4788,9 +4788,9 @@ Change annotation to attribute
47884788
class SymfonyRoute
47894789
{
47904790
- /**
4791-
- * @Route("/path", name="action") api route
4791+
- * @Route("/path", name="action")
47924792
- */
4793-
+ #[Route(path: '/path', name: 'action')] // api route
4793+
+ #[Route(path: '/path', name: 'action')]
47944794
public function action()
47954795
{
47964796
}

rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/with_comment.php.inc

Lines changed: 0 additions & 45 deletions
This file was deleted.

rules/Php80/Rector/Class_/AnnotationToAttributeRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function getRuleDefinition(): RuleDefinition
8080
class SymfonyRoute
8181
{
8282
/**
83-
* @Route("/path", name="action") api route
83+
* @Route("/path", name="action")
8484
*/
8585
public function action()
8686
{
@@ -93,7 +93,7 @@ public function action()
9393
9494
class SymfonyRoute
9595
{
96-
#[Route(path: '/path', name: 'action')] // api route
96+
#[Route(path: '/path', name: 'action')]
9797
public function action()
9898
{
9999
}

src/BetterPhpDocParser/PhpDoc/DoctrineAnnotationTagValueNode.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
88
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\AbstractValuesAwareNode;
99
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
10-
use Rector\NodeTypeResolver\Node\AttributeKey;
1110
use Stringable;
1211

1312
final class DoctrineAnnotationTagValueNode extends AbstractValuesAwareNode implements Stringable
@@ -19,16 +18,11 @@ public function __construct(
1918
public IdentifierTypeNode $identifierTypeNode,
2019
?string $originalContent = null,
2120
array $values = [],
22-
?string $silentKey = null,
23-
?string $comment = null
21+
?string $silentKey = null
2422
) {
2523
$this->hasChanged = true;
2624

2725
parent::__construct($values, $originalContent, $silentKey);
28-
29-
if (! in_array($comment, ['', null], true)) {
30-
$this->setAttribute(AttributeKey::ATTRIBUTE_COMMENT, $comment);
31-
}
3226
}
3327

3428
public function __toString(): string

src/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,6 @@ private function createDoctrineSpacelessPhpDocTagNode(
496496
$currentPhpNode
497497
);
498498

499-
$comment = $this->staticDoctrineAnnotationParser->getCommentFromRestOfAnnotation(
500-
$nestedTokenIterator,
501-
$annotationContent
502-
);
503-
504499
$identifierTypeNode = new IdentifierTypeNode($tagName);
505500
$identifierTypeNode->setAttribute(PhpDocAttributeKey::RESOLVED_CLASS, $fullyQualifiedAnnotationClass);
506501

@@ -509,7 +504,6 @@ private function createDoctrineSpacelessPhpDocTagNode(
509504
$annotationContent,
510505
$values,
511506
SilentKeyMap::CLASS_NAMES_TO_SILENT_KEYS[$fullyQualifiedAnnotationClass] ?? null,
512-
$comment
513507
);
514508

515509
$doctrineAnnotationTagValueNode->setAttribute(PhpDocAttributeKey::START_AND_END, $startAndEnd);

src/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,13 @@
1414
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\PlainValueParser;
1515
use Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator;
1616
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
17-
use Rector\Util\NewLineSplitter;
1817

1918
/**
2019
* Better version of doctrine/annotation - with phpdoc-parser and static reflection
2120
* @see \Rector\Tests\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\StaticDoctrineAnnotationParserTest
2221
*/
2322
final readonly class StaticDoctrineAnnotationParser
2423
{
25-
/**
26-
* @var string
27-
* @see https://regex101.com/r/Pthg5d/1
28-
*/
29-
private const END_OF_VALUE_CHARACTERS_REGEX = '/^[)} \r\n"\']+$/i';
30-
3124
public function __construct(
3225
private PlainValueParser $plainValueParser,
3326
private ArrayParser $arrayParser
@@ -87,24 +80,6 @@ public function resolveAnnotationValue(
8780
];
8881
}
8982

90-
public function getCommentFromRestOfAnnotation(
91-
BetterTokenIterator $tokenIterator,
92-
string $annotationContent
93-
): string {
94-
// we skip all the remaining tokens from the end of the declaration of values
95-
while (
96-
preg_match(self::END_OF_VALUE_CHARACTERS_REGEX, $tokenIterator->currentTokenValue())
97-
) {
98-
$tokenIterator->next();
99-
}
100-
101-
// the remaining of the annotation content is the comment
102-
$comment = substr($annotationContent, $tokenIterator->currentTokenOffset());
103-
// we only keep the first line as this will be added as a line comment at the end of the attribute
104-
$commentLines = NewLineSplitter::split($comment);
105-
return $commentLines[0];
106-
}
107-
10883
/**
10984
* @see https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L1051-L1079
11085
*

src/PhpAttribute/NodeFactory/PhpAttributeGroupFactory.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,7 @@ public function create(
9797
$attributeName->setAttribute(AttributeKey::PHP_ATTRIBUTE_NAME, $annotationToAttribute->getAttributeClass());
9898

9999
$attribute = new Attribute($attributeName, $args);
100-
$attributeGroup = new AttributeGroup([$attribute]);
101-
$comment = $doctrineAnnotationTagValueNode->getAttribute(AttributeKey::ATTRIBUTE_COMMENT);
102-
if ($comment) {
103-
$attributeGroup->setAttribute(AttributeKey::ATTRIBUTE_COMMENT, $comment);
104-
}
105-
106-
return $attributeGroup;
100+
return new AttributeGroup([$attribute]);
107101
}
108102

109103
/**

0 commit comments

Comments
 (0)