Completed
Push — develop ( f5bb1e...33cc42 )
by Baptiste
02:31
created

RegistrableServicePass::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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
class RegistrableServicePass implements CompilerPassInterface
14
{
15
    private $service;
16
    private $tag;
17
18 10
    public function __construct(string $service, string $tag)
19
    {
20 10
        $this->service = $service;
21 10
        $this->tag = $tag;
22 10
    }
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
32 10 View Code Duplication
        foreach ($ids as $id => $tags) {
33 8
            foreach ($tags as $tag) {
34 8
                if (!isset($tag['class'])) {
35 4
                    throw new RuntimeException(
36 4
                        'The class attribute must be defined'
37
                    );
38
                }
39
40 4
                $definition->addMethodCall(
41 4
                    'register',
42 4
                    [$tag['class'], new Reference($id)]
43
                );
44
            }
45
        }
46 6
    }
47
}
48