Passed
Push — master ( d72858...0074fd )
by Alex
02:03
created

AddTabCompletionMatcherPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0987

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 9
cp 0.7778
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 3.0987
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 AddTabCompletionMatcherPass 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.matcher', true);
24 1
        if (empty($services)) {
25
            return;
26
        }
27
28 1
        $container->getDefinition('psysh.config')
29 1
            ->addMethodCall('addTabCompletionMatchers', [$this->matchers($services)]);
30 1
    }
31
32 1
    private function matchers(array $services): array
33
    {
34 1
        $matchers = [];
35 1
        foreach (\array_keys($services) as $id) {
36 1
            $matchers[] = new Reference($id);
37
        }
38
39 1
        return $matchers;
40
    }
41
}
42