Skip to content

Commit 524af90

Browse files
authored
Merge pull request #8 from greg0ire/nested-directories
Sort candidates by file path length
2 parents 685fa0a + 71c309a commit 524af90

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

lib/Adapter/Composer/ComposerFileToClass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ private function populateCandidates(FilePath $filePath, array $prefixes)
103103
}
104104
}
105105

106+
usort($candidates, function (array $leftCandidate, array $rightCandidate): int {
107+
return strlen($rightCandidate[0]) <=> strlen($leftCandidate[0]);
108+
});
109+
106110
return $candidates;
107111
}
108112
}

tests/Integration/Composer/ComposerFileToClassTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ public function testPsr4Fallback()
107107
]);
108108
}
109109

110+
public function testNestedPsr4Directories()
111+
{
112+
$this->loadExample('psr4-nested.json');
113+
$this->assertFilePathToClassName('/psr4/AppBundle/Foo.php', [
114+
'AppBundle\\Foo',
115+
'App\\AppBundle\\Foo'
116+
]);
117+
}
118+
119+
110120
/**
111121
* @testdox Loads from classmap
112122
*/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "dantleech/basic",
3+
"authors": [
4+
{
5+
"name": "dantleech",
6+
"email": "dan.t.leech@gmail.com"
7+
}
8+
],
9+
"require": {},
10+
"autoload": {
11+
"psr-4": {
12+
"App\\": "psr4/",
13+
"AppBundle\\": "psr4/AppBundle/"
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)