Completed
Pull Request — master (#30)
by Matthew
13:27 queued 10:46
created

Configuration::addRedis()   C

Complexity

Conditions 21
Paths 1

Size

Total Lines 63
Code Lines 51

Duplication

Lines 19
Ratio 30.16 %

Code Coverage

Tests 30
CRAP Score 49.2239

Importance

Changes 0
Metric Value
dl 19
loc 63
ccs 30
cts 50
cp 0.6
rs 5.9794
c 0
b 0
f 0
cc 21
eloc 51
nc 1
nop 0
crap 49.2239

How to fix   Long Method    Complexity   

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