From 5162bcfea5456eb827035cd249c5ace55057237b Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sun, 6 Feb 2022 12:43:47 +0100 Subject: [PATCH] Fixed discovering backed enum without space around : See https://github.com/composer/composer/issues/10498 See https://github.com/composer/composer/commit/db8ea452959a7d7fc1dbdf810756aae517474919 --- .../SourceLocator/OptimizedDirectorySourceLocator.php | 5 ++++- .../SourceLocator/OptimizedDirectorySourceLocatorTest.php | 6 ++++++ .../BetterReflection/SourceLocator/data/directory/enum.php | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php b/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php index 72c7e08e8a..26c35c557d 100644 --- a/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php +++ b/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php @@ -229,7 +229,10 @@ private function findSymbols(string $file): array $functions[] = $namespacedName; } else { if ($matches['type'][$i] === 'enum') { - $namespacedName = rtrim($namespacedName, ':'); + $colonPos = strrpos($namespacedName, ':'); + if (false !== $colonPos) { + $namespacedName = substr($namespacedName, 0, $colonPos); + } } $classes[] = $namespacedName; } diff --git a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php index 736d9b6837..a447c1b851 100644 --- a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php +++ b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php @@ -47,6 +47,12 @@ public function dataClass(): iterable 'OptimizedDirectory\\TestEnum', 'enum.php', ]; + + yield [ + 'OptimizedDirectory\\BackedByStringWithoutSpace', + 'OptimizedDirectory\\BackedByStringWithoutSpace', + 'enum.php', + ]; } /** diff --git a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/data/directory/enum.php b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/data/directory/enum.php index 1f9996f4f7..4d1a990dc5 100644 --- a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/data/directory/enum.php +++ b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/data/directory/enum.php @@ -8,3 +8,8 @@ enum TestEnum: int case ONE = 1; } + +enum BackedByStringWithoutSpace:string +{ + // cases +}