Configuration   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 146
ccs 93
cts 93
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 16 1
A addCommands() 0 17 1
A addConsumer() 0 18 1
A addRpcServer() 0 18 1
A addGeneralConsumerConfiguration() 0 47 1
1
<?php
2
3
namespace MyOnlineStore\Bundle\RabbitMqManagerBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * This bundle uses the rabbit mq bundle's configuration
11
 */
12
final class Configuration implements ConfigurationInterface
13
{
14
    /**
15
     * @inheritdoc
16
     */
17 6
    public function getConfigTreeBuilder()
18
    {
19 6
        $tree = new TreeBuilder();
20
21 6
        $rootNode = $tree->root('rabbit_mq_manager');
22
23
        $rootNode
24 6
            ->children()
25 6
                ->scalarNode('path')->defaultValue('%kernel.root_dir%/../var/supervisor/%kernel.name%')->end()
26 6
            ->end();
27 6
        $this->addCommands($rootNode);
28 6
        $this->addConsumer($rootNode);
29 6
        $this->addRpcServer($rootNode);
30
31 6
        return $tree;
32
    }
33
34
    /**
35
     * Add commands configuration
36
     *
37
     * @param ArrayNodeDefinition $node
38
     */
39 6
    protected function addCommands(ArrayNodeDefinition $node)
40 1
    {
41
        $node
42 6
            ->fixXmlConfig('command')
43 6
            ->children()
44 6
                ->arrayNode('commands')
45 6
                ->addDefaultsIfNotSet()
46 6
                    ->children()
47 6
                        ->scalarNode('cli_consumer_invoker')->defaultValue('rabbitmq-manager:consumer')->end()
48 6
                        ->scalarNode('consumers')->defaultValue('rabbitmq:consumer')->end()
49 6
                        ->scalarNode('multiple_consumers')->defaultValue('rabbitmq:multiple-consumer')->end()
50 6
                        ->scalarNode('rpc_servers')->defaultValue('rabbitmq:rpc-server')->end()
51 6
                    ->end()
52 6
                ->end()
53 6
            ->end()
54
        ;
55 6
    }
56
57
    /**
58
     * Add general and individual consumer configuration
59
     *
60
     * @param ArrayNodeDefinition $node
61
     */
62 6
    protected function addConsumer(ArrayNodeDefinition $node)
63
    {
64
        $consumerChildren = $node
65 6
            ->children()
66 6
                ->arrayNode('consumers')
67 6
                ->addDefaultsIfNotSet()
68 6
                    ->children();
69
70
        $general = $consumerChildren
71 6
                        ->arrayNode('general');
72 6
        $this->addGeneralConsumerConfiguration($general);
73
74
        $individualPrototype = $consumerChildren
75 6
                        ->arrayNode('individual')
76 6
                            ->useAttributeAsKey('consumers')
77 6
                            ->prototype('array');
78 6
        $this->addGeneralConsumerConfiguration($individualPrototype);
79 6
    }
80
81
    /**
82
     * Add general and individual consumer configuration
83
     *
84
     * @param ArrayNodeDefinition $node
85
     */
86 6
    protected function addRpcServer(ArrayNodeDefinition $node)
87
    {
88
        $consumerChildren = $node
89 6
            ->children()
90 6
            ->arrayNode('rpc_servers')
91 6
            ->addDefaultsIfNotSet()
92 6
            ->children();
93
94
        $general = $consumerChildren
95 6
            ->arrayNode('general');
96 6
        $this->addGeneralConsumerConfiguration($general);
97
98
        $individualPrototype = $consumerChildren
99 6
            ->arrayNode('individual')
100 6
            ->useAttributeAsKey('rpc_servers')
101 6
            ->prototype('array');
102 6
        $this->addGeneralConsumerConfiguration($individualPrototype);
103 6
    }
104
105
    /**
106
     * Add consumer configuration
107
     *
108
     * @param ArrayNodeDefinition $node
109
     */
110 6
    protected function addGeneralConsumerConfiguration(ArrayNodeDefinition $node)
111
    {
112
        $node
113 6
        ->normalizeKeys(false)
114 6
        ->addDefaultsIfNotSet()
115 6
            ->children()
116 6
                ->enumNode('processor')
117 6
                    ->values(['bundle', 'cli-consumer'])
118 6
                    ->defaultValue('bundle')
119 6
                ->end()
120 6
                ->integerNode('messages')
121 6
                    ->min(0)
122 6
                    ->defaultValue(0)
123 6
                ->end()
124 6
                ->booleanNode('compression')
125 6
                    ->defaultTrue()
126 6
                ->end()
127 6
                ->arrayNode('worker')
128 6
                ->addDefaultsIfNotSet()
129 6
                    ->children()
130 6
                        ->integerNode('count')
131 6
                            ->min(1)
132 6
                            ->defaultValue(1)
133 6
                        ->end()
134 6
                        ->integerNode('startsecs')
135 6
                            ->min(0)
136 6
                            ->defaultValue(0)
137 6
                        ->end()
138 6
                        ->booleanNode('autorestart')
139 6
                            ->defaultTrue()
140 6
                        ->end()
141 6
                        ->enumNode('stopsignal')
142 6
                            ->values(['TERM', 'INT', 'KILL'])
143 6
                            ->defaultValue('INT')
144 6
                        ->end()
145 6
                        ->booleanNode('stopasgroup')
146 6
                            ->defaultTrue()
147 6
                        ->end()
148 6
                        ->integerNode('stopwaitsecs')
149 6
                            ->min(0)
150 6
                            ->defaultValue(60)
151 6
                        ->end()
152 6
                    ->end()
153 6
                ->end()
154 6
            ->end()
155
        ;
156 6
    }
157
}
158