Passed
Pull Request — master (#2)
by Vincent
04:15 queued 01:21
created

Configuration::getDestinationsNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 52
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 53
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 57
ccs 52
cts 53
cp 0.9811
crap 1
rs 9.0254

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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