Completed
Pull Request — master (#840)
by Simonas
01:30
created

Configuration::getManagersNode()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 99

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 99
rs 8.0218
c 0
b 0
f 0
cc 1
nc 1
nop 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
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\DependencyInjection;
13
14
use Psr\Log\LogLevel;
15
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17
use Symfony\Component\Config\Definition\ConfigurationInterface;
18
19
class Configuration implements ConfigurationInterface
20
{
21
22
    const ONGR_CACHE_CONFIG = 'ongr.esb.cache';
23
    const ONGR_SOURCE_DIR = 'ongr.esb.source_dir';
24
    const ONGR_PROFILER_CONFIG = 'ongr.esb.profiler';
25
    const ONGR_LOGGER_CONFIG = 'ongr.esb.logger';
26
    const ONGR_ANALYSIS_CONFIG = 'ongr.esb.analysis';
27
    const ONGR_INDEXES = 'ongr.esb.indexes';
28
    const ONGR_DEFAULT_INDEX = 'ongr.esb.default_index';
29
30
    public function getConfigTreeBuilder()
31
    {
32
        $treeBuilder = new TreeBuilder();
33
        $rootNode = $treeBuilder->root('ongr_elasticsearch');
34
35
        $rootNode
36
            ->children()
37
38
            ->booleanNode('cache')
39
                ->info(
40
                    'Enables the cache handler to store important data to the cache. '.
41
                    'Default value is kernel.debug parameter.'
42
                )
43
            ->end()
44
45
            ->booleanNode('profiler')
46
                ->info(
47
                    'Enables Symfony profiler for the elasticsearch queries debug.'.
48
                    'Default value is kernel.debug parameter. '
49
                )
50
            ->end()
51
52
            ->booleanNode('logger')
53
                ->defaultTrue()
54
                ->info(
55
                    'Enables executed queries logging. Log file names are the same as index.'
56
                )
57
            ->end()
58
59
            ->scalarNode('source_directory')
60
                ->defaultValue('/src')
61
                ->info(
62
                    'If your project has different than `/src` source directory, you can specify it here '.
63
                    'to look automatically for ES documents.'
64
                )
65
            ->end()
66
67
            ->append($this->getAnalysisNode())
68
69
            ->end();
70
71
        return $treeBuilder;
72
    }
73
74
    private function getAnalysisNode(): NodeDefinition
75
    {
76
        $builder = new TreeBuilder();
77
        $node = $builder->root('analysis');
78
79
        $node
80
            ->info('Defines analyzers, normalizers, tokenizers and filters')
81
            ->addDefaultsIfNotSet()
82
            ->children()
83
                ->arrayNode('tokenizer')
84
                    ->defaultValue([])
85
                    ->prototype('variable')->end()
86
                ->end()
87
                ->arrayNode('filter')
88
                    ->defaultValue([])
89
                    ->prototype('variable')->end()
90
                ->end()
91
                ->arrayNode('analyzer')
92
                    ->defaultValue([])
93
                    ->prototype('variable')->end()
94
                ->end()
95
                ->arrayNode('normalizer')
96
                    ->defaultValue([])
97
                    ->prototype('variable')->end()
98
                ->end()
99
                ->arrayNode('char_filter')
100
                    ->defaultValue([])
101
                    ->prototype('variable')->end()
102
                ->end()
103
            ->end();
104
105
        return $node;
106
    }
107
}
108