diff --git a/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php b/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php index 071080c803d..53f51cfd272 100644 --- a/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php +++ b/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php @@ -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(); } diff --git a/tests/Issues/FqcnAnnotationToAttribute/Fixture/sub_namespace_from_use.php.inc b/tests/Issues/FqcnAnnotationToAttribute/Fixture/sub_namespace_from_use.php.inc new file mode 100644 index 00000000000..7a74f33e7e5 --- /dev/null +++ b/tests/Issues/FqcnAnnotationToAttribute/Fixture/sub_namespace_from_use.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file