Skip to content

Commit

Permalink
[Php80] Allow subnamespace from use statements support on AnnotationT…
Browse files Browse the repository at this point in the history
…oAttributeRector (#5287)

* [Php80] Allow subnamespace from use statements support on AnnotationToAttributeRector

* fix
  • Loading branch information
samsonasik authored Nov 25, 2023
1 parent 8b7829f commit 9ddef00
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ private function resolveName(string $prefix, string $tag, UseUse $useUse): strin
}

if (! $originalUseUseNode->alias instanceof Identifier) {
$lastName = $originalUseUseNode->name->getLast();
if (str_starts_with($tag, $lastName . '\\')) {
$tagName = Strings::after($tag, '\\');
return $prefix . $originalUseUseNode->name->toString() . '\\' . $tagName;
}

return $prefix . $originalUseUseNode->name->toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Core\Tests\Issues\FqcnAnnotationToAttribute\Fixture;

use Doctrine\ORM\Mapping;

/**
* @Mapping\Entity()
*/
class SubNamespaceFromUse
{
}

?>
-----
<?php

namespace Rector\Core\Tests\Issues\FqcnAnnotationToAttribute\Fixture;

use Doctrine\ORM\Mapping;

#[Mapping\Entity]
class SubNamespaceFromUse
{
}

?>

0 comments on commit 9ddef00

Please sign in to comment.