Passed
Push — master ( c2b6eb...8c3bb9 )
by Sébastien
09:25
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

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