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 +}