Completed
Branch feature/redis (23fb44)
by Matthew
05:31
created

Configuration   C

Complexity

Total Complexity 57

Size/Duplication

Total Lines 498
Duplicated Lines 21.69 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 92.03%

Importance

Changes 0
Metric Value
wmc 57
lcom 1
cbo 5
dl 108
loc 498
ccs 335
cts 364
cp 0.9203
rs 6.433
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 37 1
A setDeprecatedNode() 0 10 2
A addTimings() 0 21 1
A addOrm() 16 16 1
A addOdm() 16 16 1
A addManager() 0 18 1
A addBeanstalkd() 0 12 1
B addRetry() 0 45 1
A addPriority() 0 21 1
A addClasses() 0 20 1
A addAdmin() 15 15 1
C addRedis() 19 63 21
A addPhpRedisArgs() 0 23 3
B addPredisArgs() 10 35 5
A addRabbitMqOptions() 0 18 1
C addRabbitMqSslOptions() 0 32 8
A addRabbitMqExchange() 16 16 1
A addRabbitMqArgs() 16 16 1
B addRabbitMq() 0 38 5

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Configuration often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Configuration, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Dtc\QueueBundle\DependencyInjection;
4
5
use Dtc\QueueBundle\Manager\PriorityJobManager;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
use Symfony\Component\HttpKernel\Kernel;
9
10
class Configuration implements ConfigurationInterface
11
{
12
    /**
13
     * Generates the configuration tree.
14
     *
15
     * @return TreeBuilder
16
     */
17 4
    public function getConfigTreeBuilder()
18
    {
19 4
        $treeBuilder = new TreeBuilder();
20 4
        $rootNode = $treeBuilder->root('dtc_queue');
21
22
        $node = $rootNode
23 4
            ->children()
24 4
                ->append($this->addOrm())
25 4
                ->append($this->addOdm())
26 4
                ->append($this->addManager())
27 4
                ->append($this->addTimings())
28 4
                ->append($this->addBeanstalkd())
29 4
                ->append($this->addRabbitMq())
30 4
                ->append($this->addRedis())
31 4
                ->append($this->addAdmin())
32 4
                ->append($this->addClasses())
33 4
                ->append($this->addPriority())
34 4
                ->append($this->addRetry());
35
36 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'document_manager', 'The "%node% option is deprecated, Use "odm: { document_manager: ... }" instead.');
37 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'entity_manager', 'The "%node% option is deprecated, Use "odm: { entity_manager: ... }" instead.');
38 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'default_manager', 'The "%node% option is deprecated, Use "manager: { job: ... }" instead.');
39 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'run_manager', 'The "%node% option is deprecated, Use "manager: { run: ... }" instead.');
40 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'job_timing_manager', 'The "%node% option is deprecated, Use "manager: { job_timing: ... }" instead.');
41 4
        $node = $this->setDeprecatedNode($node, 'booleanNode', 'record_timings', 'The "%node% option is deprecated, Use "timings: { record: ... }" instead.');
42 4
        $node = $this->setDeprecatedNode($node, 'integerNode', 'record_timings_timezone_offset', 'The "%node% option is deprecated, Use "record: { timezone_offset: ... }" instead.');
43 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job', 'The "%node% option is deprecated, Use "class: { job: ... }" instead.');
44 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job_archive', 'The "%node% option is deprecated, Use "class: { job_archive: ... }" instead.');
45 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_run', 'The "%node% option is deprecated, Use "class: { run: ... }" instead.');
46 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_run_archive', 'The "%node% option is deprecated, Use "class: { run_archive: ... }" instead.');
47 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job_timing', 'The "%node% option is deprecated, Use "class: { job_timing: ... }" instead.');
48 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'priority_max', 'The "%node% option is deprecated, Use "priority: { max: ... }" instead.');
49 4
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'priority_direction', 'The "%node% option is deprecated, Use "priority: { direction: ... }" instead.');
50 4
        $node->end();
51
52 4
        return $treeBuilder;
53
    }
54
55 4
    public function setDeprecatedNode($node, $type, $name, $deprecatedMessage)
56
    {
57 4
        $node = $node->$type($name);
58
59 4
        if (Kernel::VERSION_ID >= 30400) {
60 4
            $node = $node->setDeprecated($deprecatedMessage);
61
        }
62
63 4
        return $node->end();
64
    }
65
66 4
    protected function addTimings()
67
    {
68 4
        $treeBuilder = new TreeBuilder();
69 4
        $rootNode = $treeBuilder->root('timings');
70
        $rootNode
71 4
            ->addDefaultsIfNotSet()
72 4
            ->children()
73 4
                ->booleanNode('record')
74 4
                    ->info('Set this to true to record timings (used on the Trends page)')
75 4
                    ->defaultFalse()
76 4
                ->end()
77 4
                ->floatNode('timezone_offset')
78 4
                    ->defaultValue(0)
79 4
                    ->info('Set this some integer offset from GMT in case your database is not storing things in the proper timezone and the dates look off on the Trends page')
80 4
                    ->max(24)
81 4
                    ->min(-24)
82 4
                ->end()
83 4
            ->end();
84
85 4
        return $rootNode;
86
    }
87
88 4 View Code Duplication
    protected function addOrm()
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...
89
    {
90 4
        $treeBuilder = new TreeBuilder();
91 4
        $rootNode = $treeBuilder->root('orm');
92
        $rootNode
93 4
            ->addDefaultsIfNotSet()
94 4
            ->children()
95 4
                ->scalarNode('entity_manager')
96 4
                    ->info('This only needs to be set if orm is used for any of the managers, and you do not want to use the default entity manager')
97 4
                    ->defaultValue('default')
98 4
                    ->cannotBeEmpty()
99 4
                ->end()
100 4
            ->end();
101
102 4
        return $rootNode;
103
    }
104
105 4 View Code Duplication
    protected function addOdm()
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...
106
    {
107 4
        $treeBuilder = new TreeBuilder();
108 4
        $rootNode = $treeBuilder->root('odm');
109
        $rootNode
110 4
            ->addDefaultsIfNotSet()
111 4
            ->children()
112 4
                ->scalarNode('document_manager')
113 4
                    ->info('This only needs to be set if odm is used for any of the managers, and you do not want to use the default document manager')
114 4
                    ->defaultValue('default')
115 4
                    ->cannotBeEmpty()
116 4
                ->end()
117 4
            ->end();
118
119 4
        return $rootNode;
120
    }
121
122 4
    protected function addManager()
123
    {
124 4
        $treeBuilder = new TreeBuilder();
125 4
        $rootNode = $treeBuilder->root('manager');
126
        $rootNode
127 4
            ->addDefaultsIfNotSet()
128 4
            ->children()
129 4
                ->scalarNode('job')
130 4
                    ->defaultValue('odm')
131 4
                    ->info('This can be [odm|orm|beanstalkd|rabbit_mq|redis|(your-own-custom-one)]')
132 4
                    ->cannotBeEmpty()
133 4
                ->end()
134 4
                ->scalarNode('run')->end()
135 4
                ->scalarNode('job_timing')->end()
136 4
            ->end();
137
138 4
        return $rootNode;
139
    }
140
141 4
    protected function addBeanstalkd()
142
    {
143 4
        $treeBuilder = new TreeBuilder();
144 4
        $rootNode = $treeBuilder->root('beanstalkd');
145
        $rootNode
146 4
            ->children()
147 4
                ->scalarNode('host')->end()
148 4
                ->scalarNode('tube')->end()
149 4
            ->end();
150
151 4
        return $rootNode;
152
    }
153
154 4
    protected function addRetry()
155
    {
156 4
        $treeBuilder = new TreeBuilder();
157 4
        $rootNode = $treeBuilder->root('retry');
158
        $rootNode
159 4
            ->addDefaultsIfNotSet()
160 4
            ->children()
161 4
                ->arrayNode('max')
162 4
                    ->addDefaultsIfNotSet()
163 4
                    ->children()
164 4
                        ->integerNode('retries')
165 4
                            ->info('This the maximum total number of retries of any type.')
166 4
                            ->defaultValue(3)
167 4
                        ->end()
168 4
                        ->integerNode('failures')
169 4
                            ->info('This the maximum total number of failures before a job is marked as hitting the maximum failures.')
170 4
                            ->defaultValue(1)
171 4
                        ->end()
172 4
                        ->integerNode('exceptions')
173 4
                            ->info('This the maximum total number of exceptions before a job is marked as hitting the maximum exceptions.')
174 4
                            ->defaultValue(2)
175 4
                        ->end()
176 4
                        ->integerNode('stalls')
177 4
                            ->info('This the maximum total number of exceptions before a job is marked as hitting the maximum exceptions.')
178 4
                            ->defaultValue(2)
179 4
                        ->end()
180 4
                    ->end()
181 4
                ->end()
182 4
                ->arrayNode('auto')
183 4
                    ->addDefaultsIfNotSet()
184 4
                    ->children()
185 4
                        ->booleanNode('failure')
186 4
                            ->info('Instantly re-queue the job on failure.')
187 4
                            ->defaultTrue()
188 4
                        ->end()
189 4
                        ->booleanNode('exception')
190 4
                            ->info('Instantly re-queue the job on exception.')
191 4
                            ->defaultFalse()
192 4
                        ->end()
193 4
                    ->end()
194 4
                ->end()
195 4
            ->end();
196
197 4
        return $rootNode;
198
    }
199
200 4
    protected function addPriority()
201
    {
202 4
        $treeBuilder = new TreeBuilder();
203 4
        $rootNode = $treeBuilder->root('priority');
204
        $rootNode
205 4
            ->addDefaultsIfNotSet()
206 4
            ->children()
207 4
                ->integerNode('max')
208 4
                    ->defaultValue(255)
209 4
                    ->info('Maximum priority value.')
210 4
                    ->min(1)
211 4
                ->end()
212 4
                ->enumNode('direction')
213 4
                    ->values([PriorityJobManager::PRIORITY_ASC, PriorityJobManager::PRIORITY_DESC])
214 4
                    ->info('Whether 1 is high priority or low prioirty.  '.PriorityJobManager::PRIORITY_ASC.' means 1 is low, '.PriorityJobManager::PRIORITY_DESC.' means 1 is high.')
215 4
                    ->defaultValue(PriorityJobManager::PRIORITY_DESC)
216 4
                ->end()
217 4
            ->end();
218
219 4
        return $rootNode;
220
    }
221
222 4
    protected function addClasses()
223
    {
224 4
        $treeBuilder = new TreeBuilder();
225 4
        $rootNode = $treeBuilder->root('class');
226
        $rootNode
227 4
            ->children()
228 4
                ->scalarNode('job')
229 4
                    ->info('If you want to override the Job class, put the class name here.')->end()
230 4
                ->scalarNode('job_archive')
231 4
                    ->info('If you want to override the JobArchive class, put the class name here.')->end()
232 4
                ->scalarNode('job_timing')
233 4
                    ->info('If you want to override the JobTiming class, put the class name here.')->end()
234 4
                ->scalarNode('run')
235 4
                    ->info('If you want to override the Run class, put the class name here.')->end()
236 4
                ->scalarNode('run_archive')
237 4
                    ->info('If you want to override the RunArchive class, put the class name here.')->end()
238 4
            ->end();
239
240 4
        return $rootNode;
241
    }
242
243 4 View Code Duplication
    protected function addAdmin()
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...
244
    {
245 4
        $treeBuilder = new TreeBuilder();
246 4
        $rootNode = $treeBuilder->root('admin');
247
        $rootNode
248 4
            ->addDefaultsIfNotSet()
249 4
            ->children()
250 4
                ->scalarNode('chartjs')
251 4
                    ->defaultValue('https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.min.js')
252 4
                    ->info('This can be changed to say a locally hosted path or url.')->end()
253 4
                ->end()
254 4
            ->end();
255
256 4
        return $rootNode;
257
    }
258
259 4
    protected function addRedis()
260
    {
261 4
        $treeBuilder = new TreeBuilder();
262 4
        $rootNode = $treeBuilder->root('redis');
263
        $rootNode
264 4
            ->addDefaultsIfNotSet()
265 4
            ->children()
266 4
                ->scalarNode('prefix')->defaultValue('dtc_queue_')->end()
267 4
                ->arrayNode('snc_redis')
268 4
                    ->children()
269 4
                        ->enumNode('type')
270 4
                            ->values(['predis', 'phpredis'])
271 4
                            ->defaultNull()->end()
272 4
                        ->scalarNode('alias')
273 4
                            ->defaultNull()->end()
274 4
                    ->end()
275 4 View Code Duplication
                    ->validate()->ifTrue(function ($node) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
276
                        if (isset($node['type']) && !isset($node['alias'])) {
277
                            return false;
278
                        }
279
                        if (isset($node['alias']) && !isset($node['type'])) {
280
                            return false;
281
                        }
282
283
                        return true;
284 4
                    })->thenInvalid('if alias or type is set, then both must be set')->end()
285 4
                ->end()
286 4
                ->arrayNode('predis')
287 4
                    ->children()
288 4
                        ->scalarNode('dsn')->defaultNull()->end()
289 4
                        ->append($this->addPredisArgs())
290 4
                    ->end()
291 4
                    ->validate()->ifTrue(function ($node) {
292
                        if (isset($node['dsn']) && (isset($node['connection_parameters']['host']) || isset($node['connection_parameters']['port']))) {
293
                            return false;
294
                        }
295
296
                        return true;
297 4
                    })->thenInvalid('if dsn is set, do not use connection_parameters for predis (and vice-versa)')->end()
298 4
                ->end()
299 4
                ->append($this->addPhpRedisArgs())
300 4
            ->end()
301 4
            ->validate()->ifTrue(function ($node) {
302 View Code Duplication
                if ((isset($node['predis']['dsn']) || isset($node['predis']['connection_parameters']['host'])) &&
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
303
                    (isset($node['snc_redis']['type']) || isset($node['phpredis']['host']))) {
304
                    return false;
305
                }
306 View Code Duplication
                if (isset($node['snc_redis']['type']) &&
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
307
                    (isset($node['predis']['dsn']) || isset($node['predis']['connection_parameters']['host']) ||
308
                    isset($node['phpredis']['host']))) {
309
                    return false;
310
                }
311
                if ((isset($node['phpredis']['host']) || isset($node['phpredis']['port'])) &&
312
                    (isset($node['snc_redis']['type']) || isset($node['predis']['dsn']) ||
313
                     isset($node['predis']['connection_parameters']['host']))) {
314
                    return false;
315
                }
316
317
                return true;
318 4
            })->thenInvalid('only one of [snc_redis | predis | phpredis] should be set')->end();
319
320 4
        return $rootNode;
321
    }
322
323 4
    protected function addPhpRedisArgs()
324
    {
325 4
        $treeBuilder = new TreeBuilder();
326 4
        $rootNode = $treeBuilder->root('php_redis');
327
        $rootNode
328 4
            ->children()
329 4
                ->scalarNode('host')->end()
330 4
                ->integerNode('port')->defaultValue(6379)->end()
331 4
                ->floatNode('timeout')->defaultValue(0)->end()
332 4
                ->integerNode('retry_interval')->defaultNull()->end()
333 4
                ->floatNode('read_timeout')->defaultValue(0)->end()
334 4
                ->scalarNode('auth')->end()
335 4
            ->end()
336 4
            ->validate()->ifTrue(function ($node) {
337
                if (!empty($node) && !isset($node['host'])) {
338
                    return false;
339
                }
340
341
                return true;
342 4
            })->thenInvalid('phpredis host should be set')->end();
343
344 4
        return $rootNode;
345
    }
346
347 4
    protected function addPredisArgs()
348
    {
349 4
        $treeBuilder = new TreeBuilder();
350 4
        $rootNode = $treeBuilder->root('connection_parameters');
351
        $rootNode
352 4
            ->addDefaultsIfNotSet()
353 4
            ->children()
354 4
                ->scalarNode('scheme')->defaultValue('tcp')->end()
355 4
                ->scalarNode('host')->defaultNull()->end()
356 4
                ->integerNode('port')->defaultNull()->end()
357 4
                ->scalarNode('path')->defaultNull()->end()
358 4
                ->scalarNode('database')->defaultNull()->end()
359 4
                ->scalarNode('password')->defaultNull()->end()
360 4
                ->booleanNode('async')->defaultFalse()->end()
361 4
                ->booleanNode('persistent')->defaultFalse()->end()
362 4
                ->floatNode('timeout')->defaultValue(5.0)->end()
363 4
                ->floatNode('read_write_timeout')->defaultNull()->end()
364 4
                ->scalarNode('alias')->defaultNull()->end()
365 4
                ->integerNode('weight')->defaultNull()->end()
366 4
                ->booleanNode('iterable_multibulk')->defaultFalse()->end()
367 4
                ->booleanNode('throw_errors')->defaultTrue()->end()
368 4
            ->end()
369 4 View Code Duplication
            ->validate()->ifTrue(function ($node) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
370
                if (isset($node['host']) && !isset($node['port'])) {
371
                    return false;
372
                }
373
                if (isset($node['port']) && !isset($node['host'])) {
374
                    return false;
375
                }
376
377
                return true;
378 4
            })->thenInvalid('preids connection_parameters host and port should both be set')->end();
379
380 4
        return $rootNode;
381
    }
382
383 4
    protected function addRabbitMqOptions()
384
    {
385 4
        $treeBuilder = new TreeBuilder();
386 4
        $rootNode = $treeBuilder->root('options');
387
        $rootNode
388 4
            ->children()
389 4
                ->scalarNode('insist')->end()
390 4
                ->scalarNode('login_method')->end()
391 4
                ->scalarNode('login_response')->end()
392 4
                ->scalarNode('locale')->end()
393 4
                ->floatNode('connection_timeout')->end()
394 4
                ->floatNode('read_write_timeout')->end()
395 4
                ->booleanNode('keepalive')->end()
396 4
                ->integerNode('heartbeat')->end()
397 4
            ->end();
398
399 4
        return $rootNode;
400
    }
401
402 4
    protected function addRabbitMqSslOptions()
403
    {
404 4
        $treeBuilder = new TreeBuilder();
405 4
        $rootNode = $treeBuilder->root('ssl_options');
406
        $rootNode
407 4
            ->prototype('variable')->end()
408 4
            ->validate()
409 4
                ->ifTrue(function ($node) {
410 1
                    if (!is_array($node)) {
411
                        return true;
412
                    }
413 1
                    foreach ($node as $key => $value) {
414 1
                        if (is_array($value)) {
415 1
                            if ('peer_fingerprint' !== $key) {
416 1
                                return true;
417
                            } else {
418 1
                                foreach ($value as $key1 => $value1) {
419 1
                                    if (!is_string($key1) || !is_string($value1)) {
420 1
                                        return true;
421
                                    }
422
                                }
423
                            }
424
                        }
425
                    }
426
427 1
                    return false;
428 4
                })
429 4
                ->thenInvalid('Must be key-value pairs')
430 4
            ->end();
431
432 4
        return $rootNode;
433
    }
434
435 4 View Code Duplication
    protected function addRabbitMqExchange()
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...
436
    {
437 4
        $treeBuilder = new TreeBuilder();
438 4
        $rootNode = $treeBuilder->root('exchange_args');
439
        $rootNode
440 4
            ->addDefaultsIfNotSet()
441 4
            ->children()
442 4
                ->scalarNode('exchange')->defaultValue('dtc_queue_exchange')->end()
443 4
                ->booleanNode('type')->defaultValue('direct')->end()
444 4
                ->booleanNode('passive')->defaultFalse()->end()
445 4
                ->booleanNode('durable')->defaultTrue()->end()
446 4
                ->booleanNode('auto_delete')->defaultFalse()->end()
447 4
            ->end();
448
449 4
        return $rootNode;
450
    }
451
452 4 View Code Duplication
    protected function addRabbitMqArgs()
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...
453
    {
454 4
        $treeBuilder = new TreeBuilder();
455 4
        $rootNode = $treeBuilder->root('queue_args');
456
        $rootNode
457 4
            ->addDefaultsIfNotSet()
458 4
            ->children()
459 4
                ->scalarNode('queue')->defaultValue('dtc_queue')->end()
460 4
                ->booleanNode('passive')->defaultFalse()->end()
461 4
                ->booleanNode('durable')->defaultTrue()->end()
462 4
                ->booleanNode('exclusive')->defaultFalse()->end()
463 4
                ->booleanNode('auto_delete')->defaultFalse()->end()
464 4
            ->end();
465
466 4
        return $rootNode;
467
    }
468
469 4
    protected function addRabbitMq()
470
    {
471 4
        $treeBuilder = new TreeBuilder();
472 4
        $rootNode = $treeBuilder->root('rabbit_mq');
473
        $rootNode
474 4
            ->children()
475 4
                ->scalarNode('host')->end()
476 4
                ->scalarNode('port')->end()
477 4
                ->scalarNode('user')->end()
478 4
                ->scalarNode('password')->end()
479 4
                ->scalarNode('vhost')->defaultValue('/')->end()
480 4
                ->booleanNode('ssl')->defaultFalse()->end()
481 4
                ->append($this->addRabbitMqOptions())
482 4
                ->append($this->addRabbitMqSslOptions())
483 4
                ->append($this->addRabbitMqArgs())
484 4
                ->append($this->addRabbitMqExchange())
485 4
            ->end()
486 4
            ->validate()->always(function ($node) {
487 1
                if (empty($node['ssl_options'])) {
488 1
                    unset($node['ssl_options']);
489
                }
490 1
                if (empty($node['options'])) {
491 1
                    unset($node['options']);
492
                }
493
494 1
                return $node;
495 4
            })->end()
496 4
           ->validate()->ifTrue(function ($node) {
497 1
               if (isset($node['ssl_options']) && !$node['ssl']) {
498 1
                   return true;
499
               }
500
501 1
               return false;
502 4
           })->thenInvalid('ssl must be true in order to set ssl_options')->end()
503
        ->end();
504
505
        return $rootNode;
506
    }
507
}
508