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

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 2.0005

Importance

Changes 0
Metric Value
dl 0
loc 51
ccs 18
cts 19
cp 0.9474
rs 9.069
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0005

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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