Passed
Branch master (b9c197)
by Dāvis
06:45
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 349

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 0
dl 0
loc 349
rs 8
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
2
3
namespace Sludio\HelperBundle\DependencyInjection;
4
5
use Sludio\HelperBundle\Guzzle\DataCollector\GuzzleCollector;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
use Sludio\HelperBundle\Flash\Helper\FlashAlertsHelper;
9
10
class Configuration implements ConfigurationInterface
11
{
12
    protected $alias;
13
14
    /**
15
     * Configuration constructor.
16
     *
17
     * @param $alias
18
     */
19
    public function __construct($alias)
20
    {
21
        $this->alias = $alias;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     * @throws \RuntimeException
27
     */
28
    public function getConfigTreeBuilder()
29
    {
30
        $treeBuilder = new TreeBuilder();
31
        $rootNode = $treeBuilder->root($this->alias);
32
33
        // @formatter:off
34
        $rootNode
35
            ->children()
36
                ->arrayNode('extensions')
37
                    ->addDefaultsIfNotSet()
38
                    ->children()
39
                        ->arrayNode('captcha')
40
                            ->addDefaultsIfNotSet()
41
                            ->canBeEnabled()
42
                            ->children()
43
                                ->arrayNode('clients')
44
                                    ->prototype('array')
45
                                        ->prototype('variable')->end()
46
                                    ->end()
47
                                ->end()
48
                            ->end()
49
                        ->end()
50
                        ->arrayNode('flash')
51
                            ->addDefaultsIfNotSet()
52
                            ->canBeEnabled()
53
                            ->children()
54
                                ->scalarNode('alert_template')
55
                                    ->defaultValue(FlashAlertsHelper::TEMPLATE)
56
                                ->end()
57
                                ->booleanNode('alert_use_styles')
58
                                    ->defaultValue(true)
59
                                ->end()
60
                                ->booleanNode('alert_use_scripts')
61
                                    ->defaultValue(true)
62
                                ->end()
63
                            ->end()
64
                        ->end()
65
                        ->arrayNode('guzzle')
66
                            ->addDefaultsIfNotSet()
67
                            ->canBeEnabled()
68
                            ->children()
69
                                ->arrayNode('profiler')
70
                                    ->canBeEnabled()
71
                                    ->children()
72
                                        ->integerNode('max_body_size')
73
                                            ->defaultValue(GuzzleCollector::MAX_BODY_SIZE)
74
                                        ->end()
75
                                    ->end()
76
                                ->end()
77
                                ->arrayNode('logger')
78
                                    ->canBeEnabled()
79
                                    ->children()
80
                                        ->scalarNode('service')->defaultValue(null)->end()
81
                                        ->scalarNode('format')
82
                                            ->beforeNormalization()
83
                                                ->ifInArray(['clf', 'debug', 'short'])
84
                                                ->then(function($v) {
85
                                                    return \constant('GuzzleHttp\MessageFormatter::'.strtoupper($v));
86
                                                })
87
                                            ->end()
88
                                            ->defaultValue('clf')
89
                                        ->end()
90
                                        ->scalarNode('level')
91
                                            ->beforeNormalization()
92
                                                ->ifInArray([
93
                                                    'emergency', 'alert', 'critical', 'error',
94
                                                    'warning', 'notice', 'info', 'debug',
95
                                                ])
96
                                                ->then(function($v) {
97
                                                    return \constant('Psr\Log\LogLevel::'.strtoupper($v));
98
                                                })
99
                                            ->end()
100
                                            ->defaultValue('debug')
101
                                        ->end()
102
                                    ->end()
103
                                ->end()
104
                                ->arrayNode('cache')
105
                                    ->canBeEnabled()
106
                                    ->validate()
107
                                        ->ifTrue(function($v) {
108
                                            return $v['enabled'] && null === $v['adapter'];
109
                                        })
110
                                        ->thenInvalid('The \''.$this->alias.'.guzzle.cache.adapter\' key is mandatory if you enable the cache middleware')
111
                                    ->end()
112
                                    ->children()
113
                                        ->scalarNode('adapter')->defaultValue(null)->end()
114
                                        ->booleanNode('disabled')->defaultValue(null)->end()
115
                                    ->end()
116
                                ->end()
117
                                ->arrayNode('clients')
118
                                    ->useAttributeAsKey('name')
119
                                    ->prototype('array')
120
                                        ->children()
121
                                            ->scalarNode('class')
122
                                                ->defaultValue('GuzzleHttp\Client')
123
                                            ->end()
124
                                            ->booleanNode('lazy')
125
                                                ->defaultValue(false)
126
                                            ->end()
127
                                            ->variableNode('config')->end()
128
                                            ->arrayNode('middleware')
129
                                                ->prototype('scalar')->end()
130
                                            ->end()
131
                                            ->scalarNode('alias')
132
                                                ->defaultValue(null)
133
                                            ->end()
134
                                            ->enumNode('authentication_type')
135
                                                ->values(['basic'])
136
                                                ->defaultValue('basic')
137
                                            ->end()
138
                                            ->arrayNode('credentials')
139
                                                ->canBeEnabled()
140
                                                ->addDefaultsIfNotSet()
141
                                                ->children()
142
                                                    ->scalarNode('user')
143
                                                        ->defaultValue(null)
144
                                                    ->end()
145
                                                    ->scalarNode('pass')
146
                                                        ->defaultValue(null)
147
                                                    ->end()
148
                                                ->end()
149
                                            ->end()
150
                                        ->end()
151
                                    ->end()
152
                                ->end()
153
                                ->arrayNode('mock')
154
                                    ->canBeEnabled()
155
                                    ->children()
156
                                        ->scalarNode('storage_path')->isRequired()->end()
157
                                        ->scalarNode('mode')->defaultValue('replay')->end()
158
                                        ->arrayNode('request_headers_blacklist')
159
                                            ->prototype('scalar')->end()
160
                                        ->end()
161
                                        ->arrayNode('response_headers_blacklist')
162
                                            ->prototype('scalar')->end()
163
                                        ->end()
164
                                    ->end()
165
                                ->end()
166
                            ->end()
167
                        ->end()
168
                        ->arrayNode('lexik')
169
                            ->addDefaultsIfNotSet()
170
                            ->canBeEnabled()
171
                            ->children()
172
                                ->scalarNode('default_domain')->defaultValue('messages')->end()
173
                                ->arrayNode('default_selections')
174
                                    ->addDefaultsIfNotSet()
175
                                    ->children()
176
                                        ->booleanNode('non_translated_only')->defaultValue(false)->end()
177
                                    ->end()
178
                                ->end()
179
                                ->arrayNode('empty_prefixes')
180
                                    ->defaultValue(['__', 'new_', ''])
181
                                    ->prototype('array')->end()
182
                                ->end()
183
                                ->arrayNode('editable')
184
                                    ->addDefaultsIfNotSet()
185
                                    ->children()
186
                                        ->scalarNode('type')->defaultValue('textarea')->end()
187
                                        ->scalarNode('emptytext')->defaultValue('Empty')->end()
188
                                    ->end()
189
                                ->end()
190
                            ->end()
191
                        ->end()
192
                        ->arrayNode('mobile')
193
                            ->addDefaultsIfNotSet()
194
                            ->canBeEnabled()
195
                        ->end()
196
                        ->arrayNode('oauth')
197
                            ->addDefaultsIfNotSet()
198
                            ->canBeEnabled()
199
                            ->children()
200
                                ->arrayNode('clients')
201
                                    ->prototype('array')
202
                                        ->prototype('variable')->end()
203
                                    ->end()
204
                                ->end()
205
                                ->arrayNode('custom_providers')
206
                                    ->prototype('array')
207
                                        ->prototype('variable')->end()
208
                                    ->end()
209
                                ->end()
210
                            ->end()
211
                        ->end()
212
                        ->arrayNode('openid')
213
                            ->addDefaultsIfNotSet()
214
                            ->canBeEnabled()
215
                            ->children()
216
                                ->arrayNode('clients')
217
                                    ->prototype('array')
218
                                        ->prototype('variable')->end()
219
                                    ->end()
220
                                ->end()
221
                            ->end()
222
                        ->end()
223
                        ->arrayNode('openidconnect')
224
                            ->addDefaultsIfNotSet()
225
                            ->canBeEnabled()
226
                            ->children()
227
                                ->arrayNode('clients')
228
                                    ->prototype('array')
229
                                        ->prototype('variable')->end()
230
                                    ->end()
231
                                ->end()
232
                            ->end()
233
                        ->end()
234
                        ->arrayNode('pagination')
235
                            ->addDefaultsIfNotSet()
236
                            ->canBeEnabled()
237
                            ->children()
238
                                ->arrayNode('behaviour')
239
                                    ->prototype('array')
240
                                        ->prototype('variable')->end()
241
                                    ->end()
242
                                ->end()
243
                            ->end()
244
                        ->end()
245
                        ->arrayNode('position')
246
                            ->addDefaultsIfNotSet()
247
                            ->canBeEnabled()
248
                            ->children()
249
                                ->arrayNode('field')
250
                                    ->addDefaultsIfNotSet()
251
                                    ->children()
252
                                        ->scalarNode('default')
253
                                            ->defaultValue('position')
254
                                        ->end()
255
                                        ->arrayNode('entities')
256
                                            ->prototype('scalar')->end()
257
                                        ->end()
258
                                    ->end()
259
                                ->end()
260
                            ->end()
261
                        ->end()
262
                        ->arrayNode('script')
263
                            ->addDefaultsIfNotSet()
264
                            ->canBeEnabled()
265
                            ->children()
266
                                ->booleanNode('short_functions')
267
                                    ->defaultValue(false)
268
                                ->end()
269
                            ->end()
270
                        ->end()
271
                        ->arrayNode('sitemap')
272
                            ->addDefaultsIfNotSet()
273
                            ->canBeEnabled()
274
                            ->children()
275
                                ->scalarNode('base_host')
276
                                    ->defaultValue(null)
277
                                ->end()
278
                                ->scalarNode('limit')
279
                                    ->defaultValue(null)
280
                                ->end()
281
                                ->enumNode('format')
282
                                    ->values(['simple', 'rich'])
283
                                    ->defaultValue('simple')
284
                                ->end()
285
                                ->enumNode('type')
286
                                    ->values(['simple', 'gz'])
287
                                    ->defaultValue('simple')
288
                                ->end()
289
                            ->end()
290
                        ->end()
291
                        ->arrayNode('translatable')
292
                            ->addDefaultsIfNotSet()
293
                            ->canBeEnabled()
294
                            ->children()
295
                                ->arrayNode('locales')
296
                                    ->beforeNormalization()
297
                                        ->ifString()
298
                                            ->then(function($v) {
299
                                                return preg_split('/\s*,\s*/', $v);
300
                                            })
301
                                        ->end()
302
                                    ->prototype('scalar')->end()
303
                                ->end()
304
                                ->scalarNode('default_locale')
305
                                    ->defaultValue('en')
306
                                ->end()
307
                                ->scalarNode('template')
308
                                    ->defaultValue('SludioHelperBundle:Translatable:translations.html.twig')
309
                                ->end()
310
                                ->scalarNode('table')
311
                                    ->defaultValue('sludio_helper_translation')
312
                                ->end()
313
                                ->scalarNode('manager')
314
                                    ->defaultValue('default')
315
                                ->end()
316
                                ->arrayNode('entities')
317
                                    ->useAttributeAsKey('name')
318
                                    ->prototype('array')
319
                                        ->children()
320
                                            ->scalarNode('entity')
321
                                                ->defaultValue(null)
322
                                            ->end()
323
                                            ->arrayNode('fields')
324
                                                ->useAttributeAsKey('name')
325
                                                ->prototype('array')
326
                                                    ->children()
327
                                                        ->enumNode('class')
328
                                                            ->values(['titled', 'slugged', 'ck_item', null])
329
                                                            ->defaultValue(null)
330
                                                        ->end()
331
                                                        ->enumNode('type')
332
                                                            ->values(['text', 'ckeditor'])
333
                                                            ->defaultValue('text')
334
                                                        ->end()
335
                                                    ->end()
336
                                                ->end()
337
                                            ->end()
338
                                        ->end()
339
                                    ->end()
340
                                ->end()
341
                            ->end()
342
                        ->end()
343
                    ->end()
344
                ->end()
345
                ->arrayNode('other')
346
                    ->addDefaultsIfNotSet()
347
                    ->children()
348
                        ->arrayNode('redis')
349
                            ->addDefaultsIfNotSet()
350
                            ->children()
351
                                ->scalarNode('translation')
352
                                    ->defaultValue('session')
353
                                ->end()
354
                                ->scalarNode('guzzle')
355
                                    ->defaultValue('session')
356
                                ->end()
357
                            ->end()
358
                        ->end()
359
                        ->arrayNode('entity')
360
                            ->addDefaultsIfNotSet()
361
                            ->children()
362
                                ->scalarNode('manager')
363
                                    ->defaultValue('default')
364
                                ->end()
365
                            ->end()
366
                        ->end()
367
                        ->scalarNode('locale')
368
                            ->defaultValue('en')
369
                        ->end()
370
                    ->end()
371
                ->end()
372
            ->end()
373
        ;
374
        // @formatter:on
375
376
        return $treeBuilder;
377
    }
378
}
379