Skip to content

Commit a2d586f

Browse files
committed
Fixed prefix resolution
1 parent 1025b81 commit a2d586f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/Adapter/Composer/Psr0NameInflector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ final class Psr0NameInflector implements NameInflector
99
{
1010
public function inflectToRelativePath(string $prefix, ClassName $className, string $mappedPath): FilePath
1111
{
12-
if (substr($prefix, -1) !== '\\' && $className->beginsWith($prefix)) {
13-
$className = substr($className, strlen($prefix));
12+
if (substr($prefix, -1) === '_' && $className->beginsWith($prefix)) {
13+
$elements = explode('_', $className);
14+
$className = implode('\\', $elements);
1415
}
1516

1617
$relativePath = str_replace('\\', '/', $className).'.php';

tests/Integration/Composer/ComposerClassToFileTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,16 @@ public function testPsr0Fallback()
9999
public function testPsr0ShortNamePrefix()
100100
{
101101
$this->loadExample('psr0-short-prefix.json');
102-
$this->assertClassNameToFilePath('Twig_Extension', [ 'psr0/twig/Extension.php' ]);
102+
$this->assertClassNameToFilePath('Twig_Extension', [ 'psr0/twig/Twig/Extension.php' ]);
103103
}
104104

105+
public function testPsr0ShortNamePrefix2()
106+
{
107+
$this->loadExample('psr0-short-prefix.json');
108+
$this->assertClassNameToFilePath('Twig_Tests_Extension', [ 'psr0/twig/Twig/Tests/Extension.php' ]);
109+
}
110+
111+
105112
/**
106113
* @testdox PSR-4 fallback
107114
*/

0 commit comments

Comments
 (0)