RegisterTagMapPass::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Neo4jBundle\DependencyInjection\Compiler;
5
6
use Innmind\Neo4jBundle\Exception\RuntimeException;
7
use Symfony\Component\DependencyInjection\{
8
    ContainerBuilder,
9
    Compiler\CompilerPassInterface,
10
    Reference
11
};
12
13
final class RegisterTagMapPass implements CompilerPassInterface
14
{
15
    private $service;
16
    private $tag;
17
18 12
    public function __construct(string $service, string $tag)
19
    {
20 12
        $this->service = $service;
21 12
        $this->tag = $tag;
22 12
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 10
    public function process(ContainerBuilder $container)
28
    {
29 10
        $definition = $container->getDefinition($this->service);
30 10
        $ids = $container->findTaggedServiceIds($this->tag);
31 10
        $services = [];
32
33 10
        foreach ($ids as $id => $tags) {
34 10
            foreach ($tags as $tag) {
35 10
                if (!isset($tag['type'])) {
36
                    throw new RuntimeException(
37
                        'The type attribute must be defined'
38
                    );
39
                }
40
41 10
                $services[$tag['type']] = new Reference($id);
42
            }
43
        }
44
45 10
        $definition->replaceArgument(2, $services);
46 10
    }
47
}
48