ZenstruckElasticaExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 7
dl 0
loc 48
ccs 32
cts 32
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B loadInternal() 0 42 4
1
<?php
2
3
namespace Zenstruck\ElasticaBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\DefinitionDecorator;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\DependencyInjection\Reference;
10
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
11
12
/**
13
 * @author Kevin Bond <[email protected]>
14
 */
15
class ZenstruckElasticaExtension extends ConfigurableExtension
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 5
    protected function loadInternal(array $mergedConfig, ContainerBuilder $container)
21
    {
22 5
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
23 5
        $loader->load('services.xml');
24
25 5
        $container->setParameter('zenstruck_elastica.client.config', $mergedConfig['client']);
26 5
        $container->setParameter('zenstruck_elastica.index.name', $mergedConfig['index']['name']);
27 5
        $container->setParameter('zenstruck_elastica.index_settings', $mergedConfig['index']['settings']);
28
29 5
        if ($mergedConfig['logging']) {
30 1
            $client = $container->getDefinition('zenstruck_elastica.client');
31 1
            $client->addMethodCall('setLogger', array(new Reference('logger')));
32 1
            $client->addTag('monolog.logger', array('channel' => 'elastica'));
33 1
        }
34
35 5
        $typeContexts = array();
36
37 5
        foreach ($mergedConfig['types'] as $alias => $config) {
38 2
            $type = new DefinitionDecorator('zenstruck_elastica.type');
39 2
            $type->addArgument($alias);
40 2
            $typeId = 'zenstruck_elastica.type.'.$alias;
41 2
            $container->setDefinition($typeId, $type);
42
43 2
            $mapping = $config['mapping'];
44
45 2
            if (!is_array($mapping)) {
46 1
                $mapping = new Reference($mapping);
47 1
            }
48
49 2
            $typeContext = new DefinitionDecorator('zenstruck_elastica.type_context');
50 2
            $typeContext->setArguments(
51 2
                array(new Reference($typeId), new Reference($config['service']), $mapping)
52 2
            );
53 2
            $typeContextId = 'zenstruck_elastica.type_context.'.$alias;
54 2
            $container->setDefinition($typeContextId, $typeContext);
55
56 2
            $typeContexts[$alias] = new Reference($typeContextId);
57 5
        }
58
59 5
        $container->getDefinition('zenstruck_elastica.index_context')
60 5
            ->replaceArgument(1, $typeContexts);
61 5
    }
62
}
63