Completed
Push — master ( f20bc4...886a11 )
by Baptiste
02:52 queued 43s
created

RegistrableServicePass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 14
Ratio 70 %

Code Coverage

Tests 12
CRAP Score 4
Metric Value
dl 14
loc 20
ccs 12
cts 12
cp 1
rs 9.2
cc 4
eloc 11
nc 4
nop 1
crap 4
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
class RegistrableServicePass implements CompilerPassInterface
14
{
15
    private $service;
16
    private $tag;
17
18 5
    public function __construct(string $service, string $tag)
19
    {
20 5
        $this->service = $service;
21 5
        $this->tag = $tag;
22 5
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 5
    public function process(ContainerBuilder $container)
28
    {
29 5
        $definition = $container->getDefinition($this->service);
30 5
        $ids = $container->findTaggedServiceIds($this->tag);
31
32 5 View Code Duplication
        foreach ($ids as $id => $tags) {
33 4
            foreach ($tags as $tag) {
34 4
                if (!isset($tag['class'])) {
35 2
                    throw new RuntimeException(
36 2
                        'The class attribute must be defined'
37
                    );
38
                }
39
40 2
                $definition->addMethodCall(
41 2
                    'register',
42 2
                    [$tag['class'], new Reference($id)]
43
                );
44
            }
45
        }
46 3
    }
47
}
48