Completed
Pull Request — master (#14)
by GBProd
04:21
created

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 53
ccs 40
cts 40
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 47 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 10
    public function getConfigTreeBuilder()
19
    {
20 10
        $treeBuilder = new TreeBuilder();
21 10
        $rootNode = $treeBuilder->root('elastica_bundle');
22
23
        $rootNode
24 10
            ->children()
25 10
                ->scalarNode('logger')
26 10
                    ->defaultValue('logger')
27 10
                ->end()
28 10
                ->arrayNode('clients')
29 10
                    ->useAttributeAsKey('id')
30 10
                    ->defaultValue([])
31 10
                    ->prototype('array')
32 10
                        ->beforeNormalization()
33
                            ->ifTrue(function($values) {
34 6
                                return is_array($values) && !array_key_exists('connections', $values);
35 10
                            })
36 10
                            ->then(function($values) {
37 4
                                return ['connections' => [$values]];
38 10
                            })
39 10
                        ->end()
40 10
                        ->children()
41 10
                            ->arrayNode('connections')
42 10
                                ->requiresAtLeastOneElement()
43 10
                                ->prototype('array')
44 10
                                    ->addDefaultsIfNotSet()
45 10
                                    ->children()
46 10
                                        ->scalarNode('host')->defaultValue('127.0.0.1')->end()
47 10
                                        ->scalarNode('port')->defaultValue(9200)->end()
48 10
                                        ->scalarNode('path')->defaultNull()->end()
49 10
                                        ->scalarNode('url')->defaultNull()->end()
50 10
                                        ->scalarNode('proxy')->defaultNull()->end()
51 10
                                        ->scalarNode('transport')->defaultNull()->end()
52 10
                                        ->scalarNode('persistent')->defaultTrue()->end()
53 10
                                        ->scalarNode('timeout')->defaultNull()->end()
54 10
                                    ->end()
55 10
                                ->end()
56 10
                            ->end()
57 10
                        ->end()
58 10
                    ->end()
59 10
                ->end()
60 10
            ->end()
61
        ;
62
63 10
        return $treeBuilder;
64
    }
65
}
66