Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 37
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 44
ccs 37
cts 37
cp 1
rs 8.8571
cc 1
eloc 40
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Zenstruck\ElasticaBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
class Configuration implements ConfigurationInterface
12
{
13 5
    public function getConfigTreeBuilder()
14
    {
15 5
        $treeBuilder = new TreeBuilder();
16 5
        $rootNode = $treeBuilder->root('zenstruck_elastica');
17
        $rootNode
18 5
            ->children()
19 5
                ->booleanNode('logging')->defaultFalse()->end()
20 5
                ->variableNode('client')
21 5
                    ->isRequired()
22 5
                    ->validate()
23
                        ->ifTrue(function ($value) { return !is_array($value); })
24 5
                        ->thenInvalid('Client config must be an array.')
25 5
                    ->end()
26 5
                ->end()
27 5
                ->arrayNode('index')
28 5
                    ->children()
29 5
                        ->scalarNode('name')->isRequired()->end()
30 5
                        ->variableNode('settings')
31 5
                            ->defaultNull()
32 5
                            ->validate()
33
                                ->ifTrue(function ($value) { return !is_array($value); })
34 5
                                ->thenInvalid('Index settings must be an array.')
35 5
                            ->end()
36 5
                        ->end()
37 5
                    ->end()
38 5
                ->end()
39 5
                ->arrayNode('types')
40 5
                    ->useAttributeAsKey('alias')
41 5
                        ->prototype('array')
42 5
                            ->children()
43 5
                                ->scalarNode('service')->isRequired()->end()
44 5
                                ->variableNode('mapping')
45 5
                                    ->info('Can be an array of mappings or a service that implements Zenstruck\ElasticaBundle\Elastica\MappingProvider or Elastica\Type\Mapping')
46 5
                                    ->isRequired()
47 5
                                ->end()
48 5
                            ->end()
49 5
                        ->end()
50 5
                    ->end()
51 5
                ->end()
52 5
            ->end()
53
        ;
54
55 5
        return $treeBuilder;
56
    }
57
}
58