Test Failed
Push — master ( 2530ac...3f2955 )
by Vincent
10:10 queued 07:25
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 151
Duplicated Lines 0 %

Test Coverage

Coverage 97.37%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 113
c 1
b 0
f 0
dl 0
loc 151
ccs 111
cts 114
cp 0.9737
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 13 1
A getConnectionsNode() 0 53 1
A getDestinationsNode() 0 57 1
A __construct() 0 3 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
                ->append($this->getConnectionsNode())
38 1
                ->append($this->getDestinationsNode())
39 1
            ->end()
40
        ;
41
42 1
        return $treeBuilder;
43
    }
44
45
    /**
46
     * @return NodeDefinition
47
     */
48 1
    private function getConnectionsNode()
49
    {
50 1
        $root = (new TreeBuilder('connections'))->getRootNode();
51
        $root
52 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

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