Completed
Pull Request — master (#30)
by Matthew
06:35
created

Configuration::addRedis()   C

Complexity

Conditions 20
Paths 1

Size

Total Lines 63
Code Lines 51

Duplication

Lines 19
Ratio 30.16 %

Code Coverage

Tests 46
CRAP Score 20.2048

Importance

Changes 0
Metric Value
dl 19
loc 63
ccs 46
cts 50
cp 0.92
rs 5.9952
c 0
b 0
f 0
cc 20
eloc 51
nc 1
nop 0
crap 20.2048

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