Passed
Push — master ( 35ed1d...654348 )
by Dāvis
03:01
created

Configuration::createMockNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
use Sludio\HelperBundle\Guzzle\DataCollector\GuzzleCollector;
0 ignored issues
show
Bug introduced by
The type Sludio\HelperBundle\Guzz...llector\GuzzleCollector was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use GuzzleHttp\MessageFormatter;
9
10
class Configuration implements ConfigurationInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function getConfigTreeBuilder()
16
    {
17
        $treeBuilder = new TreeBuilder();
18
        $rootNode = $treeBuilder->root('sludio_helper');
19
20
        // @formatter:off
21
        $rootNode
22
            ->children()
23
                ->arrayNode('extensions')
24
                    ->addDefaultsIfNotSet()
25
                    ->children()
26
                        ->arrayNode('captcha')
27
                            ->addDefaultsIfNotSet()
28
                            ->canBeEnabled()
29
                            ->children()
30
                                ->arrayNode('clients')
31
                                    ->prototype('array')
32
                                        ->prototype('variable')->end()
33
                                    ->end()
34
                                ->end()
35
                            ->end()
36
                        ->end()
37
                        ->arrayNode('guzzle')
38
                            ->addDefaultsIfNotSet()
39
                            ->canBeEnabled()
40
                            ->children()
41
                                ->arrayNode('profiler')
42
                                    ->canBeEnabled()
43
                                    ->children()
44
                                        ->integerNode('max_body_size')
45
                                            ->defaultValue(GuzzleCollector::MAX_BODY_SIZE)
46
                                        ->end()
47
                                    ->end()
48
                                ->end()
49
                                ->arrayNode('logger')
50
                                    ->canBeEnabled()
51
                                    ->children()
52
                                        ->scalarNode('service')->defaultValue(null)->end()
53
                                        ->scalarNode('format')
54
                                            ->beforeNormalization()
55
                                                ->ifInArray(['clf', 'debug', 'short'])
56
                                                ->then(function ($v) {
57
                                                    return constant('GuzzleHttp\MessageFormatter::'.strtoupper($v));
58
                                                })
59
                                            ->end()
60
                                            ->defaultValue(MessageFormatter::CLF)
61
                                        ->end()
62
                                        ->scalarNode('level')
63
                                            ->beforeNormalization()
64
                                                ->ifInArray([
65
                                                    'emergency', 'alert', 'critical', 'error',
66
                                                    'warning', 'notice', 'info', 'debug',
67
                                                ])
68
                                                ->then(function ($v) {
69
                                                    return constant('Psr\Log\LogLevel::'.strtoupper($v));
70
                                                })
71
                                            ->end()
72
                                            ->defaultValue('debug')
73
                                        ->end()
74
                                    ->end()
75
                                ->end()
76
                                ->append($this->createCacheNode())
77
                                ->append($this->createClientsNode())
78
                                ->append($this->createMockNode())
79
                            ->end()
80
                        ->end()
81
                        ->arrayNode('lexik')
82
                            ->addDefaultsIfNotSet()
83
                            ->canBeEnabled()
84
                            ->children()
85
                                ->scalarNode('default_domain')->defaultValue('messages')->end()
86
                                ->arrayNode('default_selections')
87
                                    ->addDefaultsIfNotSet()
88
                                    ->children()
89
                                        ->booleanNode('non_translated_only')->defaultValue(false)->end()
90
                                    ->end()
91
                                ->end()
92
                                ->arrayNode('empty_prefixes')
93
                                    ->defaultValue(array('__', 'new_', ''))
94
                                    ->prototype('array')->end()
95
                                ->end()
96
                                ->arrayNode('editable')
97
                                    ->addDefaultsIfNotSet()
98
                                    ->children()
99
                                        ->scalarNode('type')->defaultValue('textarea')->end()
100
                                        ->scalarNode('emptytext')->defaultValue('Empty')->end()
101
                                    ->end()
102
                                ->end()
103
                            ->end()
104
                        ->end()
105
                        ->arrayNode('oauth')
106
                            ->addDefaultsIfNotSet()
107
                            ->canBeEnabled()
108
                            ->children()
109
                                ->arrayNode('clients')
110
                                    ->prototype('array')
111
                                        ->prototype('variable')->end()
112
                                    ->end()
113
                                ->end()
114
                                ->arrayNode('custom_providers')
115
                                    ->prototype('array')
116
                                        ->prototype('variable')->end()
117
                                    ->end()
118
                                ->end()
119
                            ->end()
120
                        ->end()
121
                        ->arrayNode('openid')
122
                            ->addDefaultsIfNotSet()
123
                            ->canBeEnabled()
124
                            ->children()
125
                                ->arrayNode('clients')
126
                                    ->prototype('array')
127
                                        ->prototype('variable')->end()
128
                                    ->end()
129
                                ->end()
130
                            ->end()
131
                        ->end()
132
                        ->arrayNode('openidconnect')
133
                            ->addDefaultsIfNotSet()
134
                            ->canBeEnabled()
135
                            ->children()
136
                                ->arrayNode('clients')
137
                                    ->prototype('array')
138
                                        ->prototype('variable')->end()
139
                                    ->end()
140
                                ->end()
141
                            ->end()
142
                        ->end()
143
                        ->arrayNode('pagination')
144
                            ->addDefaultsIfNotSet()
145
                            ->canBeEnabled()
146
                            ->children()
147
                                ->arrayNode('behaviour')
148
                                    ->prototype('array')
149
                                        ->prototype('variable')->end()
150
                                    ->end()
151
                                ->end()
152
                            ->end()
153
                        ->end()
154
                        ->arrayNode('position')
155
                            ->addDefaultsIfNotSet()
156
                            ->canBeEnabled()
157
                            ->children()
158
                                ->arrayNode('field')
159
                                    ->addDefaultsIfNotSet()
160
                                    ->children()
161
                                        ->scalarNode('default')
162
                                            ->defaultValue('position')
163
                                        ->end()
164
                                        ->arrayNode('entities')
165
                                            ->prototype('scalar')->end()
166
                                        ->end()
167
                                    ->end()
168
                                ->end()
169
                            ->end()
170
                        ->end()
171
                        ->arrayNode('script')
172
                            ->addDefaultsIfNotSet()
173
                            ->canBeEnabled()
174
                            ->children()
175
                                ->booleanNode('short_functions')
176
                                    ->defaultValue(false)
177
                                ->end()
178
                            ->end()
179
                        ->end()
180
                        ->arrayNode('translatable')
181
                            ->addDefaultsIfNotSet()
182
                            ->canBeEnabled()
183
                            ->children()
184
                                ->arrayNode('locales')
185
                                    ->beforeNormalization()
186
                                        ->ifString()
187
                                            ->then(function($v) {
188
                                                return preg_split('/\s*,\s*/', $v);
189
                                            })
190
                                        ->end()
191
                                    ->prototype('scalar')->end()
192
                                ->end()
193
                                ->scalarNode('default_locale')
194
                                    ->defaultValue('en')
195
                                ->end()
196
                                ->scalarNode('template')
197
                                    ->defaultValue('SludioHelperBundle:Translatable:translations.html.twig')
198
                                ->end()
199
                                ->scalarNode('table')
200
                                    ->defaultValue('sludio_helper_translation')
201
                                ->end()
202
                                ->scalarNode('manager')
203
                                    ->defaultValue('default')
204
                                ->end()
205
                            ->end()
206
                        ->end()
207
                    ->end()
208
                ->end()
209
                ->arrayNode('other')
210
                    ->addDefaultsIfNotSet()
211
                    ->children()
212
                        ->arrayNode('logger')
213
                            ->addDefaultsIfNotSet()
214
                            ->children()
215
                                ->scalarNode('class')
216
                                    ->defaultValue('Sludio\HelperBundle\Logger\SludioLogger')
217
                                ->end()
218
                            ->end()
219
                        ->end()
220
                        ->arrayNode('redis')
221
                            ->addDefaultsIfNotSet()
222
                            ->children()
223
                                ->scalarNode('translation')
224
                                    ->defaultValue('session')
225
                                ->end()
226
                            ->end()
227
                        ->end()
228
                        ->arrayNode('entity')
229
                            ->addDefaultsIfNotSet()
230
                            ->children()
231
                                ->scalarNode('manager')
232
                                    ->defaultValue('default')
233
                                ->end()
234
                            ->end()
235
                        ->end()
236
                        ->scalarNode('locale')
237
                            ->defaultValue('en')
238
                        ->end()
239
                    ->end()
240
                ->end()
241
            ->end()
242
        ;
243
        // @formatter:on
244
245
        return $treeBuilder;
246
    }
247
248
    private function createCacheNode()
249
    {
250
        $treeBuilder = new TreeBuilder();
251
        $node = $treeBuilder->root('cache');
252
253
        // @formatter:off
254
        $node
255
            ->canBeEnabled()
0 ignored issues
show
Bug introduced by
The method canBeEnabled() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

255
            ->/** @scrutinizer ignore-call */ 
256
              canBeEnabled()
Loading history...
256
            ->validate()
257
                ->ifTrue(function($v) {
258
                    return $v['enabled'] && null === $v['adapter'];
259
                })
260
                ->thenInvalid('The \'sludio_helper.guzzle.cache.adapter\' key is mandatory if you enable the cache middleware')
261
            ->end()
262
            ->children()
263
                ->scalarNode('adapter')->defaultNull()->end()
264
            ->end()
265
        ;
266
        // @formatter:on
267
268
        return $node;
269
    }
270
271
    private function createClientsNode()
272
    {
273
        $treeBuilder = new TreeBuilder();
274
        $node = $treeBuilder->root('clients');
275
276
        // @formatter:off
277
        $node
278
            ->useAttributeAsKey('name')
0 ignored issues
show
Bug introduced by
The method useAttributeAsKey() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

278
            ->/** @scrutinizer ignore-call */ 
279
              useAttributeAsKey('name')
Loading history...
279
            ->prototype('array')
280
                ->children()
281
                    ->scalarNode('class')
282
                        ->defaultValue('GuzzleHttp\Client')
283
                    ->end()
284
                    ->booleanNode('lazy')
285
                        ->defaultFalse()
286
                    ->end()
287
                    ->variableNode('config')->end()
288
                    ->arrayNode('middleware')
289
                        ->prototype('scalar')->end()
290
                    ->end()
291
                    ->scalarNode('alias')->defaultNull()->end()
292
                ->end()
293
            ->end()
294
        ;
295
        // @formatter:on
296
297
        return $node;
298
    }
299
300
    private function createMockNode()
301
    {
302
        $treeBuilder = new TreeBuilder();
303
        $node = $treeBuilder->root('mock');
304
305
        // @formatter:off
306
        $node
307
            ->canBeEnabled()
308
            ->children()
309
                ->scalarNode('storage_path')->isRequired()->end()
310
                ->scalarNode('mode')->defaultValue('replay')->end()
311
                ->arrayNode('request_headers_blacklist')
312
                    ->prototype('scalar')->end()
313
                ->end()
314
                ->arrayNode('response_headers_blacklist')
315
                    ->prototype('scalar')->end()
316
                ->end()
317
            ->end()
318
        ;
319
        // @formatter:on
320
321
        return $node;
322
    }
323
}
324