Completed
Push — compat-sf4 ( e31973...002b62 )
by Kevin
08:31
created

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 54
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 51 2
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('zenstruck_elastica');
16
17
        // Keep compatibility with symfony/config < 4.2
18 5
        if (\method_exists($treeBuilder, 'getRootNode')) {
19 5
            $rootNode = $treeBuilder->getRootNode();
20
        } else {
21
            $rootNode = $treeBuilder->root('zenstruck_elastica');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
22
        }
23
24
        $rootNode
25 5
            ->children()
26 5
                ->booleanNode('logging')->defaultFalse()->end()
27 5
                ->variableNode('client')
28 5
                    ->isRequired()
29 5
                    ->validate()
30
                        ->ifTrue(function ($value) { return !is_array($value); })
31 5
                        ->thenInvalid('Client config must be an array.')
32 5
                    ->end()
33 5
                ->end()
34 5
                ->arrayNode('index')
35 5
                    ->children()
36 5
                        ->scalarNode('name')->isRequired()->end()
37 5
                        ->variableNode('settings')
38 5
                            ->defaultNull()
39 5
                            ->validate()
40
                                ->ifTrue(function ($value) { return !is_array($value); })
41
                                ->thenInvalid('Index settings must be an array.')
42
                            ->end()
43
                        ->end()
44
                    ->end()
45
                ->end()
46
                ->arrayNode('types')
47
                    ->useAttributeAsKey('alias')
48
                        ->prototype('array')
49
                            ->children()
50
                                ->scalarNode('service')->isRequired()->end()
51
                                ->variableNode('mapping')
52
                                    ->info('Can be an array of mappings or a service that implements Zenstruck\ElasticaBundle\Elastica\MappingProvider or Elastica\Type\Mapping')
53
                                    ->isRequired()
54
                                ->end()
55
                            ->end()
56
                        ->end()
57
                    ->end()
58
                ->end()
59
            ->end()
60
        ;
61
62
        return $treeBuilder;
63
    }
64
}
65