Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Adapter/Composer/ClassmapNameInflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -16,4 +18,9 @@ public function inflectToClassName(FilePath $filePath, string $pathPrefix, strin
{
return ClassName::fromString($classPrefix);
}

public function getNamespaceSeparator(): string
{
return self::NAMESPACE_SEPARATOR;
}
}
14 changes: 4 additions & 10 deletions lib/Adapter/Composer/ComposerClassToFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
],
];
}
Expand All @@ -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 = [];
Expand Down
2 changes: 2 additions & 0 deletions lib/Adapter/Composer/NameInflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions lib/Adapter/Composer/Psr0NameInflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ public function inflectToClassName(FilePath $filePath, string $pathPrefix, strin

return ClassName::fromString($className);
}

public function getNamespaceSeparator(): string
{
return self::NAMESPACE_SEPARATOR;
}
}
5 changes: 5 additions & 0 deletions lib/Adapter/Composer/Psr4NameInflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public function inflectToClassName(FilePath $filePath, string $pathPrefix, strin

return ClassName::fromString($className);
}

public function getNamespaceSeparator(): string
{
return self::NAMESPACE_SEPARATOR;
}
}