RegisterRepositoriesPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
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
final class RegisterRepositoriesPass implements CompilerPassInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 6
    public function process(ContainerBuilder $container)
19
    {
20 6
        $definition = $container->getDefinition('innmind_neo4j.repository_factory.configurator');
21 6
        $ids = $container->findTaggedServiceIds('innmind_neo4j.repository');
22
23 6
        foreach ($ids as $id => $tags) {
24 4
            foreach ($tags as $tag) {
25 4
                if (!isset($tag['class'])) {
26 2
                    throw new RuntimeException(
27 2
                        'The class attribute must be defined'
28
                    );
29
                }
30
31 2
                $definition->addMethodCall(
32 2
                    'register',
33 2
                    [$tag['class'], new Reference($id)]
34
                );
35
            }
36
        }
37 4
    }
38
}
39