Passed
Pull Request — master (#2)
by Vincent
02:59
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Test Coverage

Coverage 97.48%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 118
c 1
b 0
f 0
dl 0
loc 156
ccs 116
cts 119
cp 0.9748
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 1
    public function __construct($debug = false)
23
    {
24 1
        $this->debug = (bool) $debug;
25 1
    }
26
27
    /**
28
     * {@inheritDoc}
29
     */
30 1
    public function getConfigTreeBuilder()
31
    {
32 1
        $treeBuilder = new TreeBuilder('bdf_queue');
33 1
        $treeBuilder->getRootNode()
34 1
            ->children()
35 1
                ->scalarNode('default_connection')->defaultNull()->end()
36 1
                ->scalarNode('default_serializer')->defaultValue('bdf')->end()
37 1
                ->scalarNode('failer')
38 1
                    ->info('A DSN with failer configuration; Format: [memory|prime]://{connection}/{table}')
39 1
                    ->defaultValue('memory:')
40 1
                    ->cannotBeEmpty()
41 1
                ->end()
42 1
                ->append($this->getConnectionsNode())
43 1
                ->append($this->getDestinationsNode())
44 1
            ->end()
45
        ;
46
47 1
        return $treeBuilder;
48
    }
49
50
    /**
51
     * @return NodeDefinition
52
     */
53 1
    private function getConnectionsNode()
54
    {
55 1
        $root = (new TreeBuilder('connections'))->getRootNode();
56
        $root
57 1
            ->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 1
            ->useAttributeAsKey('name')
59 1
            ->arrayPrototype()
60 1
            ->isRequired()
61 1
            ->beforeNormalization()
62 1
                ->ifString()
63
                ->then(static function ($v) {
64
                    return ['url' => $v];
65 1
                })
66 1
            ->end()
67 1
            ->children()
68 1
                ->scalarNode('url')
69 1
                    ->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 1
                    ->defaultNull()
71 1
                ->end()
72 1
                ->scalarNode('driver')->defaultNull()->end()
73 1
                ->scalarNode('vendor')->defaultNull()->end()
74 1
                ->scalarNode('queue')->defaultNull()->end()
75 1
                ->scalarNode('host')->defaultNull()->end()
76 1
                ->scalarNode('port')->defaultNull()->end()
77 1
                ->scalarNode('user')->defaultNull()->end()
78 1
                ->scalarNode('password')->defaultNull()->end()
79 1
                ->arrayNode('serializer')
80 1
                    ->addDefaultsIfNotSet()
81 1
                    ->beforeNormalization()
82 1
                        ->ifString()
83
                        ->then(static function ($v) {
84
                            return ['id' => $v];
85 1
                        })
86 1
                    ->end()
87 1
                    ->children()
88 1
                        ->scalarNode('id')
89 1
                            ->info('The serializer ID. This ID will be prefix by "bdf_queue.serializer". Defined values: native, bdf, bdf_json.')
90 1
                        ->end()
91 1
                        ->scalarNode('service')
92 1
                            ->info('The serializer service ID.')
93 1
                        ->end()
94 1
                    ->end()
95 1
                ->end()
96 1
                ->arrayNode('options')
97 1
                    ->useAttributeAsKey('key')
98 1
                    ->variablePrototype()->end()
99 1
                ->end()
100 1
                ->scalarNode('connection_factory')
101 1
                    ->defaultNull()
102 1
                ->end()
103 1
            ->end();
104
105 1
        return $root;
106
    }
107
108
    /**
109
     * @return NodeDefinition
110
     */
111 1
    private function getDestinationsNode()
112
    {
113 1
        $root = (new TreeBuilder('destinations'))->getRootNode();
114
        $root
115 1
            ->requiresAtLeastOneElement()
116 1
            ->useAttributeAsKey('name')
117 1
            ->arrayPrototype()
118 1
            ->isRequired()
119 1
            ->beforeNormalization()
120 1
                ->ifString()
121
                ->then(static function ($v) {
122
                    return ['url' => $v];
123 1
                })
124 1
            ->end()
125 1
            ->children()
126 1
                ->scalarNode('url')
127 1
                    ->info('A URL with destination information; Format: [queue|queues|topic]://{connection}/{queue}')
128 1
                    ->cannotBeEmpty()
129 1
                ->end()
130 1
                ->arrayNode('consumer')
131 1
                    ->children()
132 1
                        ->scalarNode('handler')
133 1
                            ->info('Set unique handler as outlet receiver')
134 1
                            ->defaultNull()->end()
135 1
                        ->scalarNode('retry')
136 1
                            ->info('Retry failed jobs (i.e. throwing an exception)')
137 1
                            ->defaultNull()->end()
138 1
                        ->scalarNode('max')
139 1
                            ->info('Limit the number of received message. When the limit is reached, the consumer is stopped')
140 1
                            ->defaultNull()->end()
141 1
                        ->scalarNode('limit')
142 1
                            ->info('Limit the received message rate')
143 1
                            ->defaultNull()->end()
144 1
                        ->scalarNode('memory')
145 1
                            ->info('Limit the total memory usage of the current runtime in bytes. When the limit is reached, the consumer is stopped')
146 1
                            ->defaultNull()->end()
147 1
                        ->booleanNode('save')
148 1
                            ->info('Store the failed messages')
149 1
                            ->defaultNull()->end()
150 1
                        ->booleanNode('no_failure')
151 1
                            ->info('Catch all exceptions to ensure that the consumer will no crash (and will silently fail)')
152 1
                            ->defaultNull()->end()
153 1
                        ->booleanNode('stop_when_empty')
154 1
                            ->info('Stops consumption when the destination is empty (i.e. no messages are received during the waiting duration)')
155 1
                            ->defaultNull()->end()
156 1
                        ->booleanNode('auto_handle')
157 1
                            ->info('Set auto discover as outlet receiver. The message should contain target hint.')
158 1
                            ->defaultNull()->end()
159 1
                        ->arrayNode('middlewares')
160 1
                            ->useAttributeAsKey('name')
161 1
                            ->variablePrototype()->end()
162 1
                        ->end()
163 1
                    ->end()
164 1
                ->end()
165 1
            ->end();
166
167 1
        return $root;
168
    }
169
}
170