Completed
Pull Request — master (#1343)
by Dmitry
04:26
created

ConfigSourcePass::process()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5.0729

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
ccs 6
cts 7
cp 0.8571
cc 5
eloc 13
nc 4
nop 1
crap 5.0729
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\ElasticaBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class ConfigSourcePass implements CompilerPassInterface
19
{
20
    const SOURCE_TYPE_INDEX_TEMPLATE = 'index_template';
21
22
    /**
23 8
     * {@inheritdoc}
24
     */
25 8
    public function process(ContainerBuilder $container)
26
    {
27
        if (!$container->hasDefinition('fos_elastica.config_manager')) {
28
            return;
29 8
        }
30 8
31 8
        $indexSources = [];
32
        $indexTemplateSources = [];
33
        foreach (array_keys($container->findTaggedServiceIds('fos_elastica.config_source')) as $id) {
34 8
            $tag = $container->findDefinition($id)->getTag('fos_elastica.config_source');
35 8
            if (isset($tag[0]['source']) && $tag[0]['source'] === self::SOURCE_TYPE_INDEX_TEMPLATE) {
36
                $indexTemplateSources[] = new Reference($id);
37
            } else {
38
                $indexSources[] = new Reference($id);
39
            }
40
        }
41
42
        $container->getDefinition('fos_elastica.config_manager')->replaceArgument(0, $indexSources);
43
        $container->getDefinition('fos_elastica.config_manager')->replaceArgument(1, $indexTemplateSources);
44
    }
45
}
46