Passed
Push — master ( ed42e4...b3b06a )
by Kirill
04:44
created

StaticLocator::locateCommands()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Console;
13
14
use Psr\Container\ContainerInterface;
15
use Spiral\Core\Container;
16
17
final class StaticLocator implements LocatorInterface
18
{
19
    /** @var []string */
0 ignored issues
show
Documentation Bug introduced by
The doc comment []string at position 0 could not be parsed: Unknown type name '[' at position 0 in []string.
Loading history...
20
    private $commands;
21
22
    /** @var ContainerInterface */
23
    private $factory;
24
25
    /**
26
     * @param array               $commands
27
     * @param  ContainerInterface $container
28
     */
29
    public function __construct(array $commands, ContainerInterface $container = null)
30
    {
31
        $this->commands = $commands;
32
        $this->factory = $container ?? new Container();
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function locateCommands(): array
39
    {
40
        $commands = [];
41
        foreach ($this->commands as $command) {
42
            $commands[] = $this->factory->get($command);
43
        }
44
45
        return $commands;
46
    }
47
}
48