Completed
Push — master ( 8581f0...7552d8 )
by GBProd
10s
created

QueryFactoryPass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
ccs 17
cts 17
cp 1
rs 8.439
cc 5
eloc 13
nc 5
nop 1
crap 5
1
<?php
2
3
namespace GBProd\DoctrineSpecificationBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Register doctrine QueryFactory
11
 *
12
 * @author gbprod
13
 */
14
class QueryFactoryPass implements CompilerPassInterface
15
{
16
    /**
17
     * {inheritdoc}
18
     */
19 4
    public function process(ContainerBuilder $container)
20
    {
21 4
        if (!$container->has('gbprod.doctrine_specification_handler')) {
22 1
            throw new \Exception('Missing gbprod.doctrine_specification_handler definition');
23
        }
24
25
        $handler = $container
26 3
            ->findDefinition('gbprod.doctrine_specification_handler')
27 3
        ;
28
29 3
        $builders = $container->findTaggedServiceIds('doctrine.query_factory');
30
31 3
        foreach ($builders as $id => $tags) {
32 2
            foreach ($tags as $attributes) {
33 2
                if (!isset($attributes['specification'])) {
34 1
                    throw new \Exception('The doctrine.query_factory tag must always have a "specification" attribute');
35
                }
36
37 1
                $handler->addMethodCall(
38 1
                    'registerFactory',
39 1
                    [$attributes['specification'], new Reference($id)]
40 1
                );
41 1
            }
42 2
        }
43 2
    }
44
}
45