QueryFactoryPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 25 5
1
<?php
2
3
namespace GBProd\ElasticaSpecificationBundle\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 elastica query factories
11
 *
12
 * @author GBProd <[email protected]>
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.elastica_specification_handler')) {
22 1
            throw new \Exception('Missing gbprod.elastica_specification_handler definition');
23
        }
24
25 3
        $handler = $container->findDefinition('gbprod.elastica_specification_handler');
26
27 3
        $factories = $container->findTaggedServiceIds('elastica.query_factory');
28
29 3
        foreach ($factories as $id => $tags) {
30 2
            foreach ($tags as $attributes) {
31 2
                if (!isset($attributes['specification'])) {
32 1
                    throw new \Exception(
33 1
                        'The elastica.query_factory tag must always have a "specification" attribute'
34
                    );
35
                }
36
37 1
                $handler->addMethodCall(
38 1
                    'registerFactory',
39 1
                    [$attributes['specification'], new Reference($id)]
40
                );
41
            }
42
        }
43 2
    }
44
}
45