ConsoleCommandPass::process()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Cocotte\DependencyInjection;
4
5
use Symfony\Component\Console\Application;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
final class ConsoleCommandPass implements CompilerPassInterface
11
{
12
13
    public function process(ContainerBuilder $container)
14
    {
15
        $ids = array_keys($container->findTaggedServiceIds('console.command', true));
16
17
        $refs = array_map(
18
            function ($id) {
19
                return new Reference($id);
20
            },
21
            $ids
22
        );
23
24
        $console = $container->getDefinition(Application::class);
25
        $console->addMethodCall('addCommands', [$refs]);
26
    }
27
}
28