Total Complexity | 10 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Coverage | 90.91% |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class ComposerDirectoryNamespaceLocatorStrategy implements LocatorStrategyInterface |
||
10 | { |
||
11 | 1 | use IsPluginTrait; |
|
12 | |||
13 | /** |
||
14 | * @var ClassLoader |
||
15 | */ |
||
16 | private $classLoader; |
||
17 | |||
18 | /** |
||
19 | * ComposerNamespaceLocatorStrategy constructor. |
||
20 | * @param ClassLoader $classLoader |
||
21 | */ |
||
22 | 2 | public function __construct(ClassLoader $classLoader) |
|
23 | { |
||
24 | 2 | $this->classLoader = $classLoader; |
|
25 | 2 | } |
|
26 | |||
27 | /** |
||
28 | * @return array |
||
29 | */ |
||
30 | 2 | public function locate(): array |
|
31 | { |
||
32 | 2 | $list = [[]]; |
|
33 | |||
34 | 2 | foreach($this->classLoader->getPrefixesPsr4() as $namespace => $rootDirs){ |
|
35 | 2 | foreach($rootDirs as $rootDir){ |
|
36 | 2 | if(!is_dir($rootDir)){ |
|
37 | trigger_error(sprintf('Composer directory %s does not exist', $rootDir), E_USER_WARNING); |
||
38 | continue; |
||
39 | } |
||
40 | |||
41 | 2 | $list[] = $this->locateInDirectory($namespace, $rootDir); |
|
42 | } |
||
43 | } |
||
44 | |||
45 | 2 | return array_merge(...$list); |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param string $rootNamespace |
||
50 | * @param string $rootDir |
||
51 | * @return array |
||
52 | */ |
||
53 | 2 | private function locateInDirectory(string $rootNamespace, string $rootDir): array |
|
69 | } |
||
70 | } |