CommandHydrator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 47
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A hydrateCommands() 0 7 2
A getCommandsFromFinder() 0 13 2
1
<?php
2
3
4
namespace Nexus\CustomCommand\Business\Model\Hydrator;
5
6
7
use Nexus\CustomCommand\Business\Model\Finder\CommandFinderInterface;
8
9
class CommandHydrator implements CommandHydratorInterface
10
{
11
    /**
12
     * @var \Nexus\CustomCommand\Business\Model\Finder\CommandFinderInterface
13
     */
14
    private $commandFinder;
15
16
    /**
17
     * CommandHydrator constructor.
18
     *
19
     * @param \Nexus\CustomCommand\Business\Model\Finder\CommandFinderInterface $commandFinder
20
     */
21 3
    public function __construct(CommandFinderInterface $commandFinder)
22
    {
23 3
        $this->commandFinder = $commandFinder;
24 3
    }
25
26
    /**
27
     * @param array $commands
28
     *
29
     * @return array
30
     */
31 3
    public function hydrateCommands(array $commands): array
32
    {
33 3
        if ($this->commandFinder->isDir()) {
34 2
            $commands = array_merge($commands, $this->getCommandsFromFinder());
35
        }
36
37 3
        return $commands;
38
    }
39
40
    /**
41
     * @return array
42
     */
43 2
    private function getCommandsFromFinder(): array
44
    {
45 2
        $commands = [];
46 2
        foreach ($this->commandFinder->getCommandClasses() as $file) {
47 2
            require_once $file->getRealPath();
48
49 2
            $className = sprintf(
50 2
                'Nexus\\CustomCommand\\Command\\%s',
51 2
                $file->getBasename('.php')
52
            );
53 2
            $commands[] = new $className();
54
        }
55 2
        return $commands;
56
    }
57
58
59
}