From b3c837f45afe568f43b2a6c151abfc6e0ef2b58b Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 6 Jun 2022 11:11:29 +0200 Subject: [PATCH] cs --- .../PhpDocParser/ClassAnnotationMatcher.php | 14 +++++++++++--- .../DoNotReplaceUnknownClassesTest.php | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php b/packages/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php index 11cf414b31c..8aa45a40465 100644 --- a/packages/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php +++ b/packages/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php @@ -77,8 +77,7 @@ private function resolveFullyQualifiedClass( Node $node, string $tag, bool $returnNullOnUnknownClass - ): ?string - { + ): ?string { $scope = $node->getAttribute(AttributeKey::SCOPE); if ($scope instanceof Scope) { @@ -93,7 +92,7 @@ private function resolveFullyQualifiedClass( return $this->resolveAsAliased($uses, $tag, $returnNullOnUnknownClass); } - if (str_starts_with($tag, '\\') && $this->reflectionProvider->hasClass($tag)) { + if ($this->isPreslashedExistingClass($tag)) { // Global or absolute Class return $tag; } @@ -138,4 +137,13 @@ private function resolveClass(?string $class, bool $returnNullOnUnknownClass): ? $resolvedClass = $this->reflectionProvider->hasClass($class) ? $class : null; return $returnNullOnUnknownClass ? $resolvedClass : $class; } + + private function isPreslashedExistingClass(string $tag): bool + { + if (! str_starts_with($tag, '\\')) { + return false; + } + + return $this->reflectionProvider->hasClass($tag); + } } diff --git a/tests/Issues/DoNotReplaceUnknownClasses/DoNotReplaceUnknownClassesTest.php b/tests/Issues/DoNotReplaceUnknownClasses/DoNotReplaceUnknownClassesTest.php index a6aed77f8c3..6d4773f853a 100644 --- a/tests/Issues/DoNotReplaceUnknownClasses/DoNotReplaceUnknownClassesTest.php +++ b/tests/Issues/DoNotReplaceUnknownClasses/DoNotReplaceUnknownClassesTest.php @@ -8,7 +8,7 @@ use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; -class DoNotReplaceUnknownClassesTest extends AbstractRectorTestCase +final class DoNotReplaceUnknownClassesTest extends AbstractRectorTestCase { /** * @dataProvider provideData()