Completed
Push — master ( 8d06a3...3a0f53 )
by Tobias
24:09
created

Configuration::addDataCollectorSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of php-cache\cache-bundle package.
5
 *
6
 * (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cache\CacheBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
18
/**
19
 * Class Configuration.
20
 *
21
 * @author Aaron Scherer <[email protected]>
22
 */
23
class Configuration implements ConfigurationInterface
24
{
25
    /**
26
     * Generates the configuration tree builder.
27
     *
28
     * @return TreeBuilder The tree builder
29
     */
30
    public function getConfigTreeBuilder()
31
    {
32
        $treeBuilder = new TreeBuilder();
33
        $rootNode    = $treeBuilder->root('cache');
34
35
        $rootNode->children()
36
            ->append($this->addSessionSupportSection())
37
            ->append($this->addDoctrineSection())
38
            ->append($this->addRouterSection())
39
            ->append($this->addAnnotationSection())
40
            ->append($this->addSerializerSection())
41
            ->append($this->addValidationSection())
42
            ->append($this->addLoggingSection())
43
            ->append($this->addDataCollectorSection())
44
            ->end();
45
46
        return $treeBuilder;
47
    }
48
49
    /**
50
     * Configure the "cache.session" section.
51
     *
52
     * @return ArrayNodeDefinition
53
     */
54 View Code Duplication
    private function addSessionSupportSection()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $tree = new TreeBuilder();
57
        $node = $tree->root('session');
58
59
        $node
60
            ->canBeEnabled()
61
            ->addDefaultsIfNotSet()
62
            ->children()
63
                ->scalarNode('service_id')->isRequired()->end()
64
                ->booleanNode('use_tagging')->defaultTrue()->end()
65
                ->scalarNode('prefix')->defaultValue('session_')->end()
66
                ->scalarNode('ttl')->end()
67
            ->end();
68
69
        return $node;
70
    }
71
72
    /**
73
     * Configure the "cache.serializer" section.
74
     *
75
     * @return ArrayNodeDefinition
76
     */
77
    private function addSerializerSection()
78
    {
79
        $tree = new TreeBuilder();
80
        $node = $tree->root('serializer');
81
82
        $node
83
            ->canBeEnabled()
84
            ->addDefaultsIfNotSet()
85
            ->children()
86
            ->scalarNode('service_id')->isRequired()->end()
87
                ->booleanNode('use_tagging')->defaultTrue()->end()
88
                ->scalarNode('prefix')->defaultValue('')->end()
89
            ->end();
90
91
        return $node;
92
    }
93
94
    /**
95
     * Configure the "cache.serializer" section.
96
     *
97
     * @return ArrayNodeDefinition
98
     */
99
    private function addValidationSection()
100
    {
101
        $tree = new TreeBuilder();
102
        $node = $tree->root('validation');
103
104
        $node
105
            ->canBeEnabled()
106
            ->addDefaultsIfNotSet()
107
            ->children()
108
                ->scalarNode('service_id')->isRequired()->end()
109
                ->booleanNode('use_tagging')->defaultTrue()->end()
110
                ->scalarNode('prefix')->defaultValue('')->end()
111
            ->end();
112
113
        return $node;
114
    }
115
116
    /**
117
     * Configure the "cache.annotation" section.
118
     *
119
     * @return ArrayNodeDefinition
120
     */
121
    private function addAnnotationSection()
122
    {
123
        $tree = new TreeBuilder();
124
        $node = $tree->root('annotation');
125
126
        $node
127
            ->canBeEnabled()
128
            ->addDefaultsIfNotSet()
129
            ->children()
130
                ->scalarNode('service_id')->isRequired()->end()
131
                ->booleanNode('use_tagging')->defaultTrue()->end()
132
                ->scalarNode('prefix')->defaultValue('')->end()
133
            ->end();
134
135
        return $node;
136
    }
137
138
    /**
139
     * @return ArrayNodeDefinition
140
     */
141
    private function addLoggingSection()
142
    {
143
        $tree = new TreeBuilder();
144
        $node = $tree->root('logging');
145
146
        $node
147
            ->canBeEnabled()
148
            ->addDefaultsIfNotSet()
149
            ->children()
150
                ->scalarNode('logger')->defaultValue('logger')->end()
151
                ->scalarNode('level')->defaultValue('info')->end()
152
            ->end();
153
154
        return $node;
155
    }
156
157
    /**
158
     * Configure the "cache.doctrine" section.
159
     *
160
     * @return ArrayNodeDefinition
161
     */
162
    private function addDoctrineSection()
163
    {
164
        $tree = new TreeBuilder();
165
        $node = $tree->root('doctrine');
166
167
        $node
168
            ->canBeEnabled()
169
            ->addDefaultsIfNotSet()
170
            ->children()
171
                ->booleanNode('use_tagging')
172
                    ->defaultTrue()
173
                ->end()
174
            ->end();
175
176
        $types = ['metadata', 'result', 'query'];
177
        foreach ($types as $type) {
178
            $node->children()
179
                    ->arrayNode($type)
180
                        ->canBeUnset()
181
                        ->children()
182
                            ->scalarNode('service_id')->isRequired()->end()
183
                            ->arrayNode('entity_managers')
184
                                ->defaultValue([])
185
                                ->beforeNormalization()
186
                                    ->ifString()
187
                                    ->then(
188
                                        function ($v) {
189
                                            return (array) $v;
190
                                        }
191
                                    )
192
                                    ->end()
193
                                    ->prototype('scalar')->end()
194
                                ->end()
195
                            ->arrayNode('document_managers')
196
                                ->defaultValue([])
197
                                ->beforeNormalization()
198
                                    ->ifString()
199
                                    ->then(
200
                                        function ($v) {
201
                                            return (array) $v;
202
                                        }
203
                                    )
204
                                ->end()
205
                                ->prototype('scalar')->end()
206
                            ->end()
207
                    ->end()
208
                ->end();
209
        }
210
211
        return $node;
212
    }
213
214
    /**
215
     * Configure the "cache.router" section.
216
     *
217
     * @return ArrayNodeDefinition
218
     */
219 View Code Duplication
    private function addRouterSection()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
220
    {
221
        $tree = new TreeBuilder();
222
        $node = $tree->root('router');
223
224
        $node
225
            ->canBeEnabled()
226
            ->addDefaultsIfNotSet()
227
            ->children()
228
                ->integerNode('ttl')
229
                    ->defaultValue(604800)
230
                ->end()
231
                ->scalarNode('service_id')
232
                    ->isRequired()
233
                ->end()
234
                ->booleanNode('use_tagging')->defaultTrue()->end()
235
                ->scalarNode('prefix')->defaultValue('')->end()
236
            ->end();
237
238
        return $node;
239
    }
240
241
    /**
242
     * @return ArrayNodeDefinition
243
     */
244
    private function addDataCollectorSection()
245
    {
246
        $tree = new TreeBuilder();
247
        $node = $tree->root('data_collector');
248
249
        $node
250
            ->children()
251
                ->booleanNode('enabled')->end()
252
            ->end();
253
254
        return $node;
255
    }
256
}
257