Completed
Push — 5.0 ( 02915c...8caff9 )
by Ruud
76:11 queued 44:23
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 60
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 60
rs 9.5555
c 1
b 0
f 1
cc 3
eloc 46
nc 4
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
namespace Kunstmaan\NodeSearchBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
use Kunstmaan\NodeSearchBundle\Helper\ElasticSearchUtil;
9
10
/**
11
 * This is the class that validates and merges configuration from your app/config files
12
 *
13
 * To learn more see {@link
14
 * http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
15
 */
16
class Configuration implements ConfigurationInterface
17
{
18
    /**
19
     * {@inheritDoc}
20
     */
21
    public function getConfigTreeBuilder()
22
    {
23
        $treeBuilder = new TreeBuilder();
24
        $rootNode    = $treeBuilder->root('kunstmaan_node_search');
25
26
        $rootNode->children()->booleanNode('enable_update_listener')->defaultTrue();
27
        $rootNode->children()->booleanNode('use_match_query_for_title')->defaultFalse();
28
29
        /** @var ArrayNodeDefinition $properties */
30
        $properties = $rootNode->children()->arrayNode('mapping')->useAttributeAsKey('name')->prototype('array');
31
32
        $types = [
33
            'token_count', 'text', 'keyword',
34
            'float', 'double', 'byte', 'short', 'integer', 'long',
35
            'date',
36
            'boolean',
37
            'binary',
38
        ];
39
        if (!ElasticSearchUtil::useVersion6()) {
40
            $types[] = 'string';
41
        }
42
43
        $properties->children()->scalarNode('type')->beforeNormalization()->ifNotInArray($types)->thenInvalid('type must be one of: ' . implode(', ', $types));
44
45
        if (ElasticSearchUtil::useVersion6()) {
46
            $properties->children()->booleanNode('fielddata');
47
            $properties->children()->booleanNode('doc_values');
48
            $properties->children()
49
                ->scalarNode('index')
50
                ->beforeNormalization()
51
                ->ifNotInArray(['true', 'false', true, false])
52
                ->thenInvalid("index must be one of: true, false");
53
        } else {
54
            $properties->children()
55
                ->scalarNode('index')
56
                ->beforeNormalization()
57
                ->ifNotInArray(['analyzed', 'not_analyzed', 'no'])
58
                ->thenInvalid("index must be one of: analyzed, not_analyzed, no");
59
            $properties->children()->booleanNode('include_in_all');
60
        }
61
62
        $properties->children()->booleanNode('store');
63
        $properties->children()->floatNode('boost');
64
        $properties->children()->scalarNode('null_value');
65
        $properties->children()->scalarNode('analyzer');
66
        $properties->children()->scalarNode('search_analyzer');
67
        $properties->children()->scalarNode('index_analyzer');
68
        $properties->children()->scalarNode('copy_to');
69
        $properties->children()->scalarNode('term_vector')->beforeNormalization()->ifNotInArray(['yes', 'no', 'with_positions', 'with_offsets', 'with_positions_offsets'])
70
            ->thenInvalid("term_vector must be one of: yes, no, with_positions, with_offsets, with_positions_offsets");
71
72
        $rootNode
73
            ->children()
74
                ->arrayNode('contexts')
75
                ->defaultValue([])
76
                ->prototype('scalar')->end()
77
            ->end();
78
79
        return $treeBuilder;
80
    }
81
}
82