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

CommandHydrator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 40
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hydrateCommands() 0 17 4
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
}