Skip to content

Commit

Permalink
improvement(resolver): only load classes as CamelCase
Browse files Browse the repository at this point in the history
  • Loading branch information
mikel00per committed Mar 11, 2024
1 parent 703a819 commit e11645e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Resolver/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
}
}

0 comments on commit e11645e

Please sign in to comment.