diff --git a/lib/Adapter/Composer/ClassmapNameInflector.php b/lib/Adapter/Composer/ClassmapNameInflector.php index c4e63ba8..e45c30f1 100644 --- a/lib/Adapter/Composer/ClassmapNameInflector.php +++ b/lib/Adapter/Composer/ClassmapNameInflector.php @@ -7,6 +7,8 @@ final class ClassmapNameInflector implements NameInflector { + public const NAMESPACE_SEPARATOR = ClassName::DEFAULT_NAMESPACE_SEPARATOR; + public function inflectToRelativePath(string $prefix, ClassName $className, string $mappedPath): FilePath { return FilePath::fromString($mappedPath); @@ -16,4 +18,9 @@ public function inflectToClassName(FilePath $filePath, string $pathPrefix, strin { return ClassName::fromString($classPrefix); } + + public function getNamespaceSeparator(): string + { + return self::NAMESPACE_SEPARATOR; + } } diff --git a/lib/Adapter/Composer/ComposerClassToFile.php b/lib/Adapter/Composer/ComposerClassToFile.php index 96ca8333..5c89daa0 100644 --- a/lib/Adapter/Composer/ComposerClassToFile.php +++ b/lib/Adapter/Composer/ComposerClassToFile.php @@ -25,8 +25,8 @@ public function classToFileCandidates(ClassName $className): FilePathCandidates { $candidates = []; foreach ($this->getStrategies() as $strategy) { - list($prefixes, $inflector, $separator) = $strategy; - $this->resolveFile($candidates, $prefixes, $inflector, $className, $separator); + [$prefixes, $inflector] = $strategy; + $this->resolveFile($candidates, $prefixes, $inflector, $className); } // order with the longest prefixes first @@ -48,28 +48,23 @@ private function getStrategies(): array [ $this->classLoader->getPrefixesPsr4(), new Psr4NameInflector(), - Psr4NameInflector::NAMESPACE_SEPARATOR, ], [ $this->classLoader->getPrefixes(), new Psr0NameInflector(), - Psr0NameInflector::NAMESPACE_SEPARATOR, ], [ $this->classLoader->getClassMap(), new ClassmapNameInflector(), - Psr4NameInflector::NAMESPACE_SEPARATOR, ], [ $this->classLoader->getFallbackDirs(), new Psr0NameInflector(), - Psr0NameInflector::NAMESPACE_SEPARATOR, ], [ $this->classLoader->getFallbackDirsPsr4(), // PSR0 name inflector works here as there is no prefix new Psr0NameInflector(), - Psr0NameInflector::NAMESPACE_SEPARATOR, ], ]; } @@ -78,10 +73,9 @@ private function resolveFile( &$candidates, array $prefixes, NameInflector $inflector, - ClassName $className, - string $separator + ClassName $className ): void { - $fileCandidates = $this->getFileCandidates($className, $prefixes, $separator); + $fileCandidates = $this->getFileCandidates($className, $prefixes, $inflector->getNamespaceSeparator()); foreach ($fileCandidates as $prefix => $files) { $prefixCandidates = []; diff --git a/lib/Adapter/Composer/NameInflector.php b/lib/Adapter/Composer/NameInflector.php index ffc1e718..bba82345 100644 --- a/lib/Adapter/Composer/NameInflector.php +++ b/lib/Adapter/Composer/NameInflector.php @@ -10,4 +10,6 @@ interface NameInflector public function inflectToRelativePath(string $prefix, ClassName $className, string $mappedPath): FilePath; public function inflectToClassName(FilePath $filePath, string $pathPrefix, string $classPrefix): ClassName; + + public function getNamespaceSeparator(): string; } diff --git a/lib/Adapter/Composer/Psr0NameInflector.php b/lib/Adapter/Composer/Psr0NameInflector.php index e6162ebd..733b6359 100644 --- a/lib/Adapter/Composer/Psr0NameInflector.php +++ b/lib/Adapter/Composer/Psr0NameInflector.php @@ -31,4 +31,9 @@ public function inflectToClassName(FilePath $filePath, string $pathPrefix, strin return ClassName::fromString($className); } + + public function getNamespaceSeparator(): string + { + return self::NAMESPACE_SEPARATOR; + } } diff --git a/lib/Adapter/Composer/Psr4NameInflector.php b/lib/Adapter/Composer/Psr4NameInflector.php index 02721881..8087d5e8 100644 --- a/lib/Adapter/Composer/Psr4NameInflector.php +++ b/lib/Adapter/Composer/Psr4NameInflector.php @@ -30,4 +30,9 @@ public function inflectToClassName(FilePath $filePath, string $pathPrefix, strin return ClassName::fromString($className); } + + public function getNamespaceSeparator(): string + { + return self::NAMESPACE_SEPARATOR; + } }