CommandHydrator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 39
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A hydrateCommands() 0 17 4
1
<?php
2
3
4
namespace Nexus\DynamicModules\Business\Model\Hydrator;
5
6
7
use Nexus\DynamicModules\Business\Model\Finder\ModuleFinderInterface;
8
use Xervice\Core\Business\Model\Locator\Locator;
9
10
class CommandHydrator implements CommandHydratorInterface
11
{
12
    /**
13
     * @var \Nexus\DynamicModules\Business\Model\Finder\ModuleFinderInterface
14
     */
15
    private $finder;
16
17
    /**
18
     * CommandHydrator constructor.
19
     *
20
     * @param \Nexus\DynamicModules\Business\Model\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, true)) {
40
                $facade = Locator::getInstance()->{$moduleName}()->facade();
41
                if (method_exists($facade, 'getCommands')) {
42
                    $commands = \array_merge($commands, $facade->getCommands());
43
                }
44
                $modulesDone[] = $moduleName;
45
            }
46
        }
47
48
        return $commands;
49
    }
50
}