diff --git a/src/Resolver/Resolver.php b/src/Resolver/Resolver.php index 539525a..551b754 100644 --- a/src/Resolver/Resolver.php +++ b/src/Resolver/Resolver.php @@ -56,12 +56,18 @@ private function searchForClasses( $classes = []; foreach (File::findPhpFilesIn($searchInDirectories) as $file) { $str = $rootPath . DIRECTORY_SEPARATOR . $directory . DIRECTORY_SEPARATOR; + /** @var string $replace */ $replace = str_replace($str, '', $file->getRealPath()); $class = trim($replace); + /** @var class-string $class */ $class = $rootNamespace . str_replace([DIRECTORY_SEPARATOR, '.php'], ['\\', ''], $class); + if (!$this->isValidPsr4($class)) { + continue; + } + $reflectionClass = new ReflectionClass($class); if ($reflectionClass->isAbstract()) { @@ -86,4 +92,9 @@ private function searchForClasses( return $classes; } + + private function isValidPsr4(string $namespace): bool + { + return !empty($namespace) && preg_match('/^(?:[A-Z][a-z0-9]*\\\\?)+$/', $namespace); + } }