Passed
Push — master ( 80ae69...77d195 )
by Alex
01:44
created

AddCommandPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 30
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A commands() 0 9 2
A process() 0 14 3
1
<?php
2
declare(strict_types=1);
3
4
namespace AlexMasterov\PsyshBundle\DependencyInjection\Compiler;
5
6
use Symfony\Component\DependencyInjection\{
7
    Compiler\CompilerPassInterface,
8
    ContainerBuilder,
9
    Reference
10
};
11
12
class AddCommandPass implements CompilerPassInterface
13
{
14
    /**
15
     * @inheritDoc
16
     */
17 1
    public function process(ContainerBuilder $container)
18
    {
19 1
        if (false === $container->has('psysh.shell')) {
20
            return;
21
        }
22
23 1
        $services = $container->findTaggedServiceIds('psysh.command', true);
24 1
        if (empty($services)) {
25
            return;
26
        }
27
28 1
        $container->getDefinition('psysh.shell')
29 1
            ->addMethodCall('addCommands', [$this->commands($services)]);
30 1
    }
31
32 1
    private function commands(array $services): array
33
    {
34 1
        $commands = [];
35 1
        foreach (\array_keys($services) as $id) {
36 1
            $commands[] = new Reference($id);
37
        }
38
39 1
        return $commands;
40
    }
41
}
42