Completed
Push — master ( 98f353...32973a )
by GBProd
04:02
created

ElasticaExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 38
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 7 1
A loadClients() 0 6 2
A loadClient() 0 7 1
A createClientId() 0 7 1
1
<?php
2
3
namespace GBProd\ElasticaBundle\DependencyInjection;
4
5
use Elastica\Client;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10
11
/**
12
 * Extension class for ElasticaExtension
13
 *
14
 * @author gbprod <[email protected]>
15
 */
16
class ElasticaExtension extends Extension
17
{
18
    const CLIENT_ID_TEMPLATE = 'elastica.%s_client';
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 2
    public function load(array $configs, ContainerBuilder $container)
24
    {
25 2
        $configuration = new Configuration();
26 2
        $config = $this->processConfiguration($configuration, $configs);
27
28 2
        $this->loadClients($config, $container);
29 2
    }
30
31 2
    private function loadClients(array $config, ContainerBuilder $container)
32
    {
33 2
        foreach ($config['clients'] as $clientName => $clientConfig) {
34 2
            $this->loadClient($clientName, $clientConfig, $container);
35 2
        }
36 2
    }
37
38 2
    private function loadClient($clientName, array $clientConfig, ContainerBuilder $container)
39
    {
40
        $container
41 2
            ->register($this->createClientId($clientName), Client::class)
42 2
            ->addArgument($clientConfig)
43
        ;
44 2
    }
45
46 2
    private function createClientId($clientName)
47
    {
48 2
        return sprintf(
49 2
            self::CLIENT_ID_TEMPLATE,
50
            $clientName
51 2
        );
52
    }
53
}