Passed
Push — master ( 3d3a35...263c14 )
by Matthew
08:06
created

RabbitMQConfiguration::addRabbitMqSslOptions()   C

Complexity

Conditions 8
Paths 1

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 8.0079

Importance

Changes 0
Metric Value
cc 8
eloc 20
nc 1
nop 0
dl 0
loc 31
ccs 19
cts 20
cp 0.95
crap 8.0079
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
namespace Dtc\QueueBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
7
trait RabbitMQConfiguration
8
{
9 9
    protected function addRabbitMqOptions()
10
    {
11 9
        $treeBuilder = new TreeBuilder();
12 9
        $rootNode = $treeBuilder->root('options');
13
        $rootNode
14 9
            ->children()
15 9
            ->scalarNode('insist')->end()
16 9
            ->scalarNode('login_method')->end()
17 9
            ->scalarNode('login_response')->end()
18 9
            ->scalarNode('locale')->end()
19 9
            ->floatNode('connection_timeout')->end()
20 9
            ->floatNode('read_write_timeout')->end()
21 9
            ->booleanNode('keepalive')->end()
22 9
            ->integerNode('heartbeat')->end()
23 9
            ->end();
24
25 9
        return $rootNode;
26
    }
27
28 9
    protected function addRabbitMqSslOptions()
29
    {
30 9
        $treeBuilder = new TreeBuilder();
31 9
        $rootNode = $treeBuilder->root('ssl_options');
32
        $rootNode
33 9
            ->prototype('variable')->end()
0 ignored issues
show
Bug introduced by
The method prototype() 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

33
            ->/** @scrutinizer ignore-call */ 
34
              prototype('variable')->end()
Loading history...
34 9
            ->validate()
35 9
            ->ifTrue(function ($node) {
36 1
                if (!is_array($node)) {
37
                    return true;
38
                }
39 1
                foreach ($node as $key => $value) {
40 1
                    if (is_array($value)) {
41 1
                        if ('peer_fingerprint' !== $key) {
42 1
                            return true;
43
                        } else {
44 1
                            foreach ($value as $key1 => $value1) {
45 1
                                if (!is_string($key1) || !is_string($value1)) {
46 1
                                    return true;
47
                                }
48
                            }
49
                        }
50
                    }
51
                }
52
53 1
                return false;
54 9
            })
55 9
            ->thenInvalid('Must be key-value pairs')
56 9
            ->end();
57
58 9
        return $rootNode;
59
    }
60
61 9
    protected function addRabbitMqExchange()
62
    {
63 9
        $treeBuilder = new TreeBuilder();
64 9
        $rootNode = $treeBuilder->root('exchange_args');
65
        $rootNode
66 9
            ->addDefaultsIfNotSet()
0 ignored issues
show
Bug introduced by
The method addDefaultsIfNotSet() 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

66
            ->/** @scrutinizer ignore-call */ 
67
              addDefaultsIfNotSet()
Loading history...
67 9
            ->children()
68 9
            ->scalarNode('exchange')->defaultValue('dtc_queue_exchange')->end()
69 9
            ->booleanNode('type')->defaultValue('direct')->end()
70 9
            ->booleanNode('passive')->defaultFalse()->end()
71 9
            ->booleanNode('durable')->defaultTrue()->end()
72 9
            ->booleanNode('auto_delete')->defaultFalse()->end()
73 9
            ->end();
74
75 9
        return $rootNode;
76
    }
77
78 9
    protected function addRabbitMqArgs()
79
    {
80 9
        $treeBuilder = new TreeBuilder();
81 9
        $rootNode = $treeBuilder->root('queue_args');
82
        $rootNode
83 9
            ->addDefaultsIfNotSet()
84 9
            ->children()
85 9
            ->scalarNode('queue')->defaultValue('dtc_queue')->end()
86 9
            ->booleanNode('passive')->defaultFalse()->end()
87 9
            ->booleanNode('durable')->defaultTrue()->end()
88 9
            ->booleanNode('exclusive')->defaultFalse()->end()
89 9
            ->booleanNode('auto_delete')->defaultFalse()->end()
90 9
            ->end();
91
92 9
        return $rootNode;
93
    }
94
95 9
    protected function addRabbitMq()
96
    {
97 9
        $treeBuilder = new TreeBuilder();
98 9
        $rootNode = $treeBuilder->root('rabbit_mq');
99
        $rootNode
100 9
            ->children()
101 9
            ->scalarNode('host')->end()
102 9
            ->scalarNode('port')->end()
103 9
            ->scalarNode('user')->end()
104 9
            ->scalarNode('password')->end()
105 9
            ->scalarNode('vhost')->defaultValue('/')->end()
106 9
            ->booleanNode('ssl')->defaultFalse()->end()
107 9
            ->append($this->addRabbitMqOptions())
108 9
            ->append($this->addRabbitMqSslOptions())
109 9
            ->append($this->addRabbitMqArgs())
110 9
            ->append($this->addRabbitMqExchange())
111 9
            ->end()
112 9
            ->validate()->always(function ($node) {
113 1
                if (empty($node['ssl_options'])) {
114 1
                    unset($node['ssl_options']);
115
                }
116 1
                if (empty($node['options'])) {
117 1
                    unset($node['options']);
118
                }
119
120 1
                return $node;
121 9
            })->end()
122 9
            ->validate()->ifTrue(function ($node) {
123 1
                if (isset($node['ssl_options']) && !$node['ssl']) {
124 1
                    return true;
125
                }
126
127 1
                return false;
128 9
            })->thenInvalid('ssl must be true in order to set ssl_options')->end()
129
            ->end();
130
131
        return $rootNode;
132
    }
133
}
134