Failed Conditions
Pull Request — master (#2)
by GBProd
02:29
created

ExpressionBuilderPass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
ccs 16
cts 16
cp 1
rs 8.5906
cc 5
eloc 12
nc 5
nop 1
crap 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 expression builder
11
 *
12
 * @author gbprod
13
 */
14
class ExpressionBuilderPass 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
        $builders = $container->findTaggedServiceIds('elastica.expression_builder');
28
29 3
        foreach ($builders as $id => $tags) {
30 2
            foreach ($tags as $attributes) {
31 2
                if (!isset($attributes['specification'])) {
32 1
                    throw new \Exception('The elastica.expression_builder tag must always have a "specification" attribute');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
33
                }
34
35 1
                $handler->addMethodCall(
36 1
                    'registerBuilder',
37 1
                    [$attributes['specification'], new Reference($id)]
38 1
                );
39 1
            }
40 2
        }
41 2
    }
42
}
43