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

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 50
ccs 37
cts 37
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 44 2
1
<?php
2
3
namespace GBProd\ElasticaBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * Configuration
10
 *
11
 * @author gbprod <[email protected]>
12
 */
13
class Configuration implements ConfigurationInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 7
    public function getConfigTreeBuilder()
19
    {
20 7
        $treeBuilder = new TreeBuilder();
21 7
        $rootNode = $treeBuilder->root('elastica_bundle');
22
23
        $rootNode
24 7
            ->children()
25 7
                ->arrayNode('clients')
26 7
                    ->useAttributeAsKey('id')
27 7
                    ->defaultValue([])
28 7
                    ->prototype('array')
29 7
                        ->beforeNormalization()
30
                            ->ifTrue(function ($values) {
31 6
                                return is_array($values) && !array_key_exists('connections', $values);
32 7
                            })
33 7
                            ->then(function ($values) {
34 4
                                return ['connections' => [$values]];
35 7
                            })
36 7
                        ->end()
37 7
                        ->children()
38 7
                            ->arrayNode('connections')
39 7
                                ->requiresAtLeastOneElement()
40 7
                                ->prototype('array')
41 7
                                    ->addDefaultsIfNotSet()
42 7
                                    ->children()
43 7
                                        ->scalarNode('host')->defaultValue('127.0.0.1')->end()
44 7
                                        ->scalarNode('port')->defaultValue(9200)->end()
45 7
                                        ->scalarNode('path')->defaultNull()->end()
46 7
                                        ->scalarNode('url')->defaultNull()->end()
47 7
                                        ->scalarNode('proxy')->defaultNull()->end()
48 7
                                        ->scalarNode('transport')->defaultNull()->end()
49 7
                                        ->scalarNode('persistent')->defaultTrue()->end()
50 7
                                        ->scalarNode('timeout')->defaultNull()->end()
51 7
                                    ->end()
52 7
                                ->end()
53 7
                            ->end()
54 7
                        ->end()
55 7
                    ->end()
56 7
                ->end()
57 7
            ->end()
58
        ;
59
60 7
        return $treeBuilder;
61
    }
62
}