Skip to content

Commit

Permalink
[PHP 8.0] Fix annotation to attribute in case of FQN class without () (
Browse files Browse the repository at this point in the history
…#5609)

* add fixture

* fix annotation to attribute in case of FQN class without ()
  • Loading branch information
TomasVotruba committed Feb 12, 2024
1 parent 14eb72c commit 6dd91df
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture\Doctrine;

/**
* @\Doctrine\ORM\Mapping\Embeddable
*/
class PreserveIntKeyDefined
{
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture\Doctrine;

#[\Doctrine\ORM\Mapping\Embeddable]
class PreserveIntKeyDefined
{
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

$rectorConfig
->ruleWithConfiguration(AnnotationToAttributeRector::class, [
new AnnotationToAttribute('Doctrine\ORM\Mapping\Embeddable'),

new AnnotationToAttribute(PastAnnotation::class, FutureAttribute::class),
new AnnotationToAttribute(NestedPastAnnotation::class, NestedFutureAttribute::class),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
private const ALLOWED_SHORT_ANNOTATIONS = ['Target'];

/**
* @see https://regex101.com/r/95kIw4/2
* @see https://regex101.com/r/bGp2V0/1
* @var string
*/
private const LONG_ANNOTATION_REGEX = '#@\\\\(?<class_name>.*?)(?<annotation_content>\(.*?\)|,)#';
private const LONG_ANNOTATION_REGEX = '#@\\\\(?<class_name>.*?)(?<annotation_content>\(.*?\)|,|\n|$)#';

/**
* @see https://regex101.com/r/xWaLOz/1
Expand Down Expand Up @@ -437,6 +437,7 @@ private function resolveFqnAnnotationSpacelessPhpDocTagNode(
Node $currentPhpNode
): array {
$matches = Strings::matchAll($phpDocTextNode->text, self::LONG_ANNOTATION_REGEX);

$spacelessPhpDocTagNodes = [];
foreach ($matches as $match) {
$fullyQualifiedAnnotationClass = $match['class_name'] ?? null;
Expand Down

0 comments on commit 6dd91df

Please sign in to comment.