Completed
Push — master ( 8cbc1b...c966cb )
by GBProd
01:57
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 47
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 40
CRAP Score 2

Importance

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