Completed
Branch master (3b2eee)
by Krzysztof
05:35
created

ChainSearchCompilerPass::addCellCollection()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.0123

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 8
cts 9
cp 0.8889
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 13
nc 3
nop 4
crap 3.0123
1
<?php
2
3
namespace KGzocha\Bundle\SearcherBundle\DependencyInjection\CompilerPass;
4
5
use KGzocha\Bundle\SearcherBundle\DependencyInjection\Configuration;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
9
/**
10
 * @author Krzysztof Gzocha <[email protected]>
11
 */
12
class ChainSearchCompilerPass extends AbstractChainsCompilerPass
13
{
14
    const CHAIN_SEARCHER = 'chain_searcher';
15
16
    /**
17
     * @inheritDoc
18
     */
19 2
    protected function processParam(
20
        $contextId,
21
        array &$paramConfig,
22
        ContainerBuilder $container
23
    ) {
24 2
        $definition = $this->buildDefinition(
25
            $container,
26
            $contextId,
27 2
            $this->buildChainServiceName(
28
                $contextId,
29 2
                self::SEARCHER_PARAMETER
30
            ),
31 2
            $paramConfig[self::CHAIN_SEARCHER]
32
        );
33
34 2
        $this->addCellCollection($contextId, $paramConfig, $container, $definition);
35 2
    }
36
37
    /**
38
     * @param string           $contextId
39
     * @param array            $paramConfig
40
     * @param ContainerBuilder $container
41
     * @param Definition       $chainSearcher
42
     */
43 2
    private function addCellCollection(
44
        $contextId,
45
        array &$paramConfig,
46
        ContainerBuilder $container,
47
        Definition $chainSearcher
48
    ) {
49 2
        if ($paramConfig[self::CHAIN_SEARCHER]['service']) {
50
            return;
51
        }
52
53 2
        if (Configuration::CHAIN_SEARCHER_CLASS !== $paramConfig[self::CHAIN_SEARCHER]['class']) {
54 1
            return;
55
        }
56
57 1
        $cellCollection = $container->getDefinition($this->buildChainServiceName(
58
            $contextId,
59 1
            CellCollectionCompilerPass::CELL_COLLECTION
60
        ));
61
62 1
        $chainSearcher->addArgument($cellCollection);
63 1
    }
64
}
65