Passed
Push — master ( 989339...709032 )
by Sébastien
03:24
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Test Coverage

Coverage 97.46%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 118
c 1
b 0
f 0
dl 0
loc 156
ccs 115
cts 118
cp 0.9746
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getConfigTreeBuilder() 0 18 1
A getConnectionsNode() 0 53 1
A getDestinationsNode() 0 57 1
1
<?php
2
3
namespace Bdf\QueueBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * Configuration
11
 */
12
class Configuration implements ConfigurationInterface
13
{
14
    /**
15
     * @var bool
16
     */
17
    private $debug;
18
19
    /**
20
     * @param bool $debug Whether to use the debug mode
21
     */
22 8
    public function __construct($debug = false)
23
    {
24 8
        $this->debug = (bool) $debug;
25
    }
26
27
    /**
28
     * {@inheritDoc}
29
     */
30 8
    public function getConfigTreeBuilder()
31
    {
32 8
        $treeBuilder = new TreeBuilder('bdf_queue');
33 8
        $treeBuilder->getRootNode()
34 8
            ->children()
35 8
                ->scalarNode('default_connection')->defaultNull()->end()
36 8
                ->scalarNode('default_serializer')->defaultValue('bdf')->end()
37 8
                ->scalarNode('failer')
38 8
                    ->info('A DSN with failer configuration; Format: [memory|prime]://{connection}/{table}')
39 8
                    ->defaultValue('memory:')
40 8
                    ->cannotBeEmpty()
41 8
                ->end()
42 8
                ->append($this->getConnectionsNode())
43 8
                ->append($this->getDestinationsNode())
44 8
            ->end()
45
        ;
46
47 8
        return $treeBuilder;
48
    }
49
50
    /**
51
     * @return NodeDefinition
52
     */
53 8
    private function getConnectionsNode()
54
    {
55 8
        $root = (new TreeBuilder('connections'))->getRootNode();
56
        $root
57 8
            ->requiresAtLeastOneElement()
0 ignored issues
show
Bug introduced by
The method requiresAtLeastOneElement() 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

57
            ->/** @scrutinizer ignore-call */ 
58
              requiresAtLeastOneElement()
Loading history...
58 8
            ->useAttributeAsKey('name')
59 8
            ->arrayPrototype()
60 8
            ->isRequired()
61 8
            ->beforeNormalization()
62 8
                ->ifString()
63 8
                ->then(static function ($v) {
64
                    return ['url' => $v];
65
                })
66 8
            ->end()
67 8
            ->children()
68 8
                ->scalarNode('url')
69 8
                    ->info('A URL with connection information; any parameter value parsed from this string will override explicitly set parameters. Format: {driver}+{vendor}://{user}:{password}@{host}:{port}/{queue}?{option}=value')
70 8
                    ->defaultNull()
71 8
                ->end()
72 8
                ->scalarNode('driver')->defaultNull()->end()
73 8
                ->scalarNode('vendor')->defaultNull()->end()
74 8
                ->scalarNode('queue')->defaultNull()->end()
75 8
                ->scalarNode('host')->defaultNull()->end()
76 8
                ->scalarNode('port')->defaultNull()->end()
77 8
                ->scalarNode('user')->defaultNull()->end()
78 8
                ->scalarNode('password')->defaultNull()->end()
79 8
                ->arrayNode('serializer')
80 8
                    ->addDefaultsIfNotSet()
81 8
                    ->beforeNormalization()
82 8
                        ->ifString()
83 8
                        ->then(static function ($v) {
84
                            return ['id' => $v];
85
                        })
86 8
                    ->end()
87 8
                    ->children()
88 8
                        ->scalarNode('id')
89 8
                            ->info('The serializer ID. This ID will be prefix by "bdf_queue.serializer". Defined values: native, bdf, bdf_json.')
90 8
                        ->end()
91 8
                        ->scalarNode('service')
92 8
                            ->info('The serializer service ID.')
93 8
                        ->end()
94 8
                    ->end()
95 8
                ->end()
96 8
                ->arrayNode('options')
97 8
                    ->useAttributeAsKey('key')
98 8
                    ->variablePrototype()->end()
99 8
                ->end()
100 8
                ->scalarNode('connection_factory')
101 8
                    ->defaultNull()
102 8
                ->end()
103 8
            ->end();
104
105 8
        return $root;
106
    }
107
108
    /**
109
     * @return NodeDefinition
110
     */
111 8
    private function getDestinationsNode()
112
    {
113 8
        $root = (new TreeBuilder('destinations'))->getRootNode();
114
        $root
115 8
            ->requiresAtLeastOneElement()
116 8
            ->useAttributeAsKey('name')
117 8
            ->arrayPrototype()
118 8
            ->isRequired()
119 8
            ->beforeNormalization()
120 8
                ->ifString()
121 8
                ->then(static function ($v) {
122
                    return ['url' => $v];
123
                })
124 8
            ->end()
125 8
            ->children()
126 8
                ->scalarNode('url')
127 8
                    ->info('A URL with destination information; Format: [queue|queues|topic]://{connection}/{queue}')
128 8
                    ->cannotBeEmpty()
129 8
                ->end()
130 8
                ->arrayNode('consumer')
131 8
                    ->children()
132 8
                        ->scalarNode('handler')
133 8
                            ->info('Set unique handler as outlet receiver')
134 8
                            ->defaultNull()->end()
135 8
                        ->scalarNode('retry')
136 8
                            ->info('Retry failed jobs (i.e. throwing an exception)')
137 8
                            ->defaultNull()->end()
138 8
                        ->scalarNode('max')
139 8
                            ->info('Limit the number of received message. When the limit is reached, the consumer is stopped')
140 8
                            ->defaultNull()->end()
141 8
                        ->scalarNode('limit')
142 8
                            ->info('Limit the received message rate')
143 8
                            ->defaultNull()->end()
144 8
                        ->scalarNode('memory')
145 8
                            ->info('Limit the total memory usage of the current runtime in bytes. When the limit is reached, the consumer is stopped')
146 8
                            ->defaultNull()->end()
147 8
                        ->booleanNode('save')
148 8
                            ->info('Store the failed messages')
149 8
                            ->defaultNull()->end()
150 8
                        ->booleanNode('no_failure')
151 8
                            ->info('Catch all exceptions to ensure that the consumer will no crash (and will silently fail)')
152 8
                            ->defaultNull()->end()
153 8
                        ->booleanNode('stop_when_empty')
154 8
                            ->info('Stops consumption when the destination is empty (i.e. no messages are received during the waiting duration)')
155 8
                            ->defaultNull()->end()
156 8
                        ->booleanNode('auto_handle')
157 8
                            ->info('Set auto discover as outlet receiver. The message should contain target hint.')
158 8
                            ->defaultNull()->end()
159 8
                        ->arrayNode('middlewares')
160 8
                            ->useAttributeAsKey('name')
161 8
                            ->variablePrototype()->end()
162 8
                        ->end()
163 8
                    ->end()
164 8
                ->end()
165 8
            ->end();
166
167 8
        return $root;
168
    }
169
}
170