Passed
Push — master ( 3128ea...1ca9c2 )
by Alex
03:18
created

AddMatchersPass::process()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 5
nop 1
crap 4
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 AddMatchersPass implements CompilerPassInterface
13
{
14
    /** {@inheritdoc} */
15 3
    public function process(ContainerBuilder $container)
16
    {
17 3
        if (!$container->has('psysh.shell')) {
18 1
            return;
19
        }
20
21 2
        $matchers = [];
22
23 2
        foreach ($container->findTaggedServiceIds('psysh.matcher', true) as $id => $tags) {
24 1
            $matchers[] = new Reference($id);
25
        }
26
27 2
        if (empty($matchers)) {
28 1
            return;
29
        }
30
31 1
        $container->getDefinition('psysh.config')
32 1
            ->addMethodCall('addMatchers', [$matchers]);
33 1
    }
34
}
35