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

KunstmaanNodeSearchExtension::prepend()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 105
Code Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 105
rs 8.2857
c 0
b 0
f 0
cc 2
eloc 75
nc 2
nop 1

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\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Kunstmaan\NodeSearchBundle\Helper\ElasticSearchUtil;
10
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
11
12
/**
13
 * This is the class that loads and manages your bundle configuration
14
 *
15
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
16
 */
17
class KunstmaanNodeSearchExtension extends Extension implements PrependExtensionInterface
18
{
19
    /**
20
     * {@inheritDoc}
21
     */
22
    public function load(array $configs, ContainerBuilder $container)
23
    {
24
        $configuration = new Configuration();
25
        $config = $this->processConfiguration($configuration, $configs);
26
27
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
28
        $loader->load('services.yml');
29
30
        if (!empty($config['enable_update_listener']) && $config['enable_update_listener']) {
31
            $loader->load('update_listener.yml');
32
        }
33
34
        if (array_key_exists('use_match_query_for_title', $config)) {
35
            $container->getDefinition('kunstmaan_node_search.search.node')
36
                ->addMethodCall('setUseMatchQueryForTitle', [$config['use_match_query_for_title']]);
37
        }
38
39
        $container->getDefinition('kunstmaan_node_search.search_configuration.node')
40
            ->addMethodCall('setDefaultProperties', [$config['mapping']]);
41
42
        $container->setParameter('kunstmaan_node_search.contexts', $config['contexts']);
43
    }
44
45
    /**
46
     * Allow an extension to prepend the extension configurations.
47
     *
48
     * @param ContainerBuilder $container
49
     */
50
    public function prepend(ContainerBuilder $container)
51
    {
52
        if (ElasticSearchUtil::useVersion6()) {
53
            $mapping = [
54
                'mapping' => [
55
                    'root_id' => [
56
                        'type' => 'integer',
57
                    ],
58
                    'node_id' => [
59
                        'type' => 'integer',
60
                    ],
61
                    'nodetranslation_id' => [
62
                        'type' => 'integer',
63
                    ],
64
                    'nodeversion_id' => [
65
                        'type' => 'integer',
66
                    ],
67
                    'title' => [
68
                        'type' => 'text',
69
                    ],
70
                    'slug' => [
71
                        'type' => 'text',
72
                    ],
73
                    'type' => [
74
                        'type' => 'keyword',
75
                    ],
76
                    'page_class' => [
77
                        'type' => 'keyword',
78
                    ],
79
                    'content' => [
80
                        'type' => 'text',
81
                    ],
82
                    'view_roles' => [
83
                        'type' => 'keyword',
84
                    ],
85
                ]
86
            ];
87
        } else {
88
            $mapping = [
89
                'mapping' => [
90
                    'root_id' => [
91
                        'type' => 'integer',
92
                        'include_in_all' => false,
93
                        'index' => 'not_analyzed'
94
                    ],
95
                    'node_id' => [
96
                        'type' => 'integer',
97
                        'include_in_all' => false,
98
                        'index' => 'not_analyzed'
99
                    ],
100
                    'nodetranslation_id' => [
101
                        'type' => 'integer',
102
                        'include_in_all' => false,
103
                        'index' => 'not_analyzed'
104
                    ],
105
                    'nodeversion_id' => [
106
                        'type' => 'integer',
107
                        'include_in_all' => false,
108
                        'index' => 'not_analyzed'
109
                    ],
110
                    'title' => [
111
                        'type' => 'string',
112
                        'boost' => 2,
113
                        'include_in_all' => true
114
                    ],
115
                    'slug' => [
116
                        'type' => 'string',
117
                        'include_in_all' => false,
118
                        'index' => 'not_analyzed'
119
                    ],
120
                    'type' => [
121
                        'type' => 'string',
122
                        'include_in_all' => false,
123
                        'index' => 'not_analyzed'
124
                    ],
125
                    'page_class' => [
126
                        'type' => 'string',
127
                        'include_in_all' => false,
128
                        'index' => 'not_analyzed'
129
                    ],
130
                    'content' => [
131
                        'type' => 'string',
132
                        'include_in_all' => true
133
                    ],
134
                    'created' => [
135
                        'type' => 'date',
136
                        'include_in_all' => false,
137
                        'index' => 'not_analyzed'
138
                    ],
139
                    'updated' => [
140
                        'type' => 'date',
141
                        'include_in_all' => false,
142
                        'index' => 'not_analyzed'
143
                    ],
144
                    'view_roles' => [
145
                        'type' => 'string',
146
                        'include_in_all' => true,
147
                        'index' => 'not_analyzed',
148
                    ],
149
                ]
150
            ];
151
        }
152
153
        $container->prependExtensionConfig('kunstmaan_node_search', $mapping);
154
    }
155
}
156