Passed
Push — master ( f7dffe...ed5e38 )
by Koldo
02:46
created

ConsoleFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 0
loc 23
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\Cli\Container;
6
7
use Antidot\Cli\Application\Console;
8
use Psr\Container\ContainerInterface;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
11
12
use function array_walk;
13
14
class ConsoleFactory
15
{
16
    public function __invoke(ContainerInterface $container): Console
17
    {
18
        $config = $container->get('config');
19
        /** @var Console $console */
20
        $console = new Console();
21
        $commands = $container->get('config')['console']['commands'] ?? [];
22
        $lazyCommands = [];
23
        foreach ($commands as $name => $command) {
24
            $lazyCommands[$name] = static function () use ($command, $container): Command {
25
                return $container->get($command);
26
            };
27
        }
28
        $console->setCommandLoader(new FactoryCommandLoader($lazyCommands));
29
        array_walk(
30
            $config['console']['helper-sets'],
31
            static function (string $helperSet) use ($console, $container): void {
32
                $console->setHelperSet($container->get($helperSet));
33
            }
34
        );
35
36
        return $console;
37
    }
38
}
39