Passed
Branch feature/options (1c5fa7)
by Alex
01:56
created

AddTabCompletionMatcherPass::matchers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 6
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
    public function process(ContainerBuilder $container)
18
    {
19
        if (false === $container->has('psysh.shell')) {
20
            return;
21
        }
22
23
        $services = $container->findTaggedServiceIds('psysh.matcher', true);
24
        if (empty($services)) {
25
            return;
26
        }
27
28
        $container->getDefinition('psysh.config')
29
            ->addMethodCall('addTabCompletionMatchers', [$this->matchers($services)]);
30
    }
31
32
    private function matchers(array $services): array
33
    {
34
        $matchers = [];
35
        foreach (\array_keys($services) as $id) {
36
            $matchers[] = new Reference($id);
37
        }
38
39
        return $matchers;
40
    }
41
}
42