Passed
Push — trunk ( e33fdd...7ae7db )
by Christian
23:22 queued 10:15
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 61
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 56
nc 1
nop 0
dl 0
loc 61
rs 8.9599
c 0
b 0
f 0

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 declare(strict_types=1);
2
3
namespace Shopware\Elasticsearch\DependencyInjection;
4
5
use Monolog\Level;
6
use Shopware\Core\DevOps\Environment\EnvironmentHelper;
7
use Shopware\Core\Framework\Log\Package;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
use Symfony\Component\Config\Definition\ConfigurationInterface;
10
11
#[Package('core')]
12
class Configuration implements ConfigurationInterface
13
{
14
    public function getConfigTreeBuilder(): TreeBuilder
15
    {
16
        $treeBuilder = new TreeBuilder('elasticsearch');
17
18
        $debug = EnvironmentHelper::getVariable('APP_ENV', 'prod') !== 'prod';
19
20
        $rootNode = $treeBuilder->getRootNode();
21
        $rootNode
22
            ->children()
23
                ->booleanNode('enabled')->end()
24
                ->booleanNode('indexing_enabled')->end()
25
                ->integerNode('indexing_batch_size')->defaultValue(100)->end()
26
                ->scalarNode('hosts')->end()
27
                ->scalarNode('index_prefix')->end()
28
                ->scalarNode('throw_exception')->end()
29
                ->scalarNode('logger_level')->defaultValue($debug ? Level::Debug : Level::Error)->end()
30
                ->arrayNode('ssl')
31
                    ->children()
32
                        ->scalarNode('cert_path')->end()
33
                        ->scalarNode('cert_password')->end()
34
                        ->scalarNode('cert_key_path')->end()
35
                        ->scalarNode('cert_key_password')->end()
36
                        ->booleanNode('verify_server_cert')->defaultValue(true)->end()
37
                    ->end()
38
                ->end()
39
                ->arrayNode('index_settings')->variablePrototype()->end()->end()
40
                ->arrayNode('analysis')->performNoDeepMerging()->variablePrototype()->end()->end()
41
                ->arrayNode('dynamic_templates')->performNoDeepMerging()->variablePrototype()->end()->end()
42
                ->arrayNode('product')
43
                    ->children()
44
                        ->arrayNode('custom_fields_mapping')
45
                            ->variablePrototype()->end()
46
                        ->end()
47
                    ->end()
48
                ->end()
49
                ->arrayNode('search')
50
                    ->children()
51
                        ->scalarNode('timeout')->end()
52
                        ->integerNode('term_max_length')->end()
53
                    ->end()
54
                ->end()
55
                ->arrayNode('administration')
56
                    ->children()
57
                        ->scalarNode('hosts')->end()
58
                        ->booleanNode('enabled')->end()
59
                        ->booleanNode('refresh_indices')->end()
60
                        ->scalarNode('index_prefix')->end()
61
                        ->arrayNode('index_settings')->variablePrototype()->end()->end()
62
                        ->arrayNode('analysis')->performNoDeepMerging()->variablePrototype()->end()->end()
63
                        ->arrayNode('dynamic_templates')->performNoDeepMerging()->variablePrototype()->end()->end()
64
                        ->arrayNode('search')
65
                            ->children()
66
                                ->scalarNode('timeout')->end()
67
                                ->integerNode('term_max_length')->end()
68
                            ->end()
69
                        ->end()
70
                    ->end()
71
                ->end()
72
            ->end();
73
74
        return $treeBuilder;
75
    }
76
}
77