Passed
Push — master ( 3376db...1497f5 )
by Mike
12:25
created

CommandHydrator::hydrateCommands()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 9.7
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 20
1
<?php
2
3
4
namespace Nexus\DynamicModules\Business\Hydrator;
5
6
7
use Nexus\DynamicModules\Business\Finder\ModuleFinderInterface;
8
use Xervice\Core\Locator\Locator;
9
10
class CommandHydrator implements CommandHydratorInterface
11
{
12
    /**
13
     * @var \Nexus\DynamicModules\Business\Finder\ModuleFinderInterface
14
     */
15
    private $finder;
16
17
    /**
18
     * CommandHydrator constructor.
19
     *
20
     * @param \Nexus\DynamicModules\Business\Finder\ModuleFinderInterface $finder
21
     */
22
    public function __construct(ModuleFinderInterface $finder)
23
    {
24
        $this->finder = $finder;
25
    }
26
27
    /**
28
     * @param array $commands
29
     *
30
     * @return array
31
     */
32
    public function hydrateCommands(array $commands) : array
33
    {
34
        $modulesDone = [];
35
36
        foreach ($this->finder->getModuleList() as $module) {
37
            $moduleName = basename($module);
38
39
            if (!in_array($moduleName, $modulesDone)) {
40
                $facade = Locator::getInstance()->{$moduleName}()->facade();
41
                if (method_exists($facade, 'getCommands')) {
42
                    $commands = array_merge($commands, $facade->getCommands());
43
                }
44
            }
45
        }
46
47
        return $commands;
48
    }
49
}