Completed
Push — master ( ca6a09...c1aa72 )
by Krzysztof
03:59
created

CriteriaBuilderCompilerPass::processContext()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 13
nc 2
nop 3
crap 2
1
<?php
2
3
namespace KGzocha\Bundle\SearcherBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * @author Krzysztof Gzocha <[email protected]>
11
 */
12
class CriteriaBuilderCompilerPass extends AbstractCompilerPass
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 2
    protected function processContext(
18
        $contextId,
19
        array &$context,
20
        ContainerBuilder $container
21
    ) {
22 2
        foreach ($context['builders'] as &$builder) {
23 2
            $definitionName = $this->processCriteriaBuilder($contextId, $builder, $container);
24
25
            $criteriaCollection = $this
26 2
                ->buildServiceName($contextId, self::BUILDER_COLLECTION_PARAMETER);
27
            $container
28 2
                ->getDefinition($criteriaCollection)
29 2
                ->addMethodCall(
30 2
                    'addCriteriaBuilder',
31 2
                    [new Reference($definitionName)]
32
                );
33
        }
34 2
    }
35
36
    /**
37
     * @param string           $contextId
38
     * @param array            $builder
39
     * @param ContainerBuilder $container
40
     *
41
     * @return string
42
     *
43
     * @throws InvalidDefinitionException
44
     */
45 2 View Code Duplication
    private function processCriteriaBuilder(
46
        $contextId,
47
        array &$builder,
48
        ContainerBuilder $container
49
    ) {
50 2
        $definitionName = $this->buildServiceName(
51
            $contextId,
52 2
            sprintf('builder.%s', $builder[self::NAME_PARAMETER])
53
        );
54
55 2
        $this->buildDefinition($container, $contextId, $definitionName, $builder);
56
57 2
        return $definitionName;
58
    }
59
}
60