Configuration::addRetry()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 51
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 42
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 44
nc 2
nop 0
dl 0
loc 51
ccs 42
cts 43
cp 0.9767
crap 2
rs 9.216
c 0
b 0
f 0

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 Dtc\QueueBundle\DependencyInjection;
4
5
use Dtc\QueueBundle\Manager\PriorityJobManager;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Config...ion\Builder\TreeBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Config...\ConfigurationInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\HttpKernel\Kernel;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKernel\Kernel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class Configuration implements ConfigurationInterface
11
{
12 1
    use RabbitMQConfiguration;
13 1
    use RedisConfiguration;
14
15
    /**
16
     * Generates the configuration tree.
17
     *
18
     * @return TreeBuilder
19
     */
20 10
    public function getConfigTreeBuilder(): TreeBuilder
21
    {
22 10
        $treeBuilder = new TreeBuilder('dtc_queue');
23
24 10
        if (method_exists($treeBuilder, 'getRootNode')) {
25 10
            $rootNode = $treeBuilder->getRootNode();
26
        } else {
27
            // BC layer for symfony/config 4.1 and older
28
            $rootNode = $treeBuilder->root('dtc_queue');
29
        }
30
31
        $node = $rootNode
32 10
            ->children()
33 10
                ->booleanNode('locale_fix')
34 10
                    ->defaultFalse()
35 10
                    ->info('Set this to true to fix issues with ORM saving (see issue #98) in non-period decimal format locales')
36 10
                ->end()
37 10
                ->append($this->addSimpleScalar('orm', 'entity_manager', 'This only needs to be set if orm is used for any of the managers, and you do not want to use the default entity manager'))
38 10
                ->append($this->addSimpleScalar('odm', 'document_manager', 'This only needs to be set if odm is used for any of the managers, and you do not want to use the default document manager'))
39 10
                ->append($this->addManager())
40 10
                ->append($this->addTimings())
41 10
                ->append($this->addBeanstalkd())
42 10
                ->append($this->addRabbitMq())
43 10
                ->append($this->addRedis())
44 10
                ->append($this->addSimpleScalar('admin', 'chartjs', 'This can be changed to say a locally hosted path or url.', 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.min.js'))
45 10
                ->append($this->addClasses())
46 10
                ->append($this->addPriority())
47 10
                ->append($this->addRetry());
48 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'document_manager', 'The "%node% option is deprecated, Use "odm: { document_manager: ... }" instead.');
49 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'entity_manager', 'The "%node% option is deprecated, Use "orm: { entity_manager: ... }" instead.');
50 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'default_manager', 'The "%node% option is deprecated, Use "manager: { job: ... }" instead.');
51 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'run_manager', 'The "%node% option is deprecated, Use "manager: { run: ... }" instead.');
52 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'job_timing_manager', 'The "%node% option is deprecated, Use "manager: { job_timing: ... }" instead.');
53 10
        $node = $this->setDeprecatedNode($node, 'booleanNode', 'record_timings', 'The "%node% option is deprecated, Use "timings: { record: ... }" instead.');
54 10
        $node = $this->setDeprecatedNode($node, 'floatNode', 'record_timings_timezone_offset', 'The "%node% option is deprecated, Use "record: { timezone_offset: ... }" instead.');
55 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job', 'The "%node% option is deprecated, Use "class: { job: ... }" instead.');
56 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job_archive', 'The "%node% option is deprecated, Use "class: { job_archive: ... }" instead.');
57 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_run', 'The "%node% option is deprecated, Use "class: { run: ... }" instead.');
58 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_run_archive', 'The "%node% option is deprecated, Use "class: { run_archive: ... }" instead.');
59 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job_timing', 'The "%node% option is deprecated, Use "class: { job_timing: ... }" instead.');
60 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'priority_max', 'The "%node% option is deprecated, Use "priority: { max: ... }" instead.');
61 10
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'priority_direction', 'The "%node% option is deprecated, Use "priority: { direction: ... }" instead.');
62 10
        $node->end();
63
64 10
        return $treeBuilder;
65
    }
66
67 10
    public function setDeprecatedNode($node, $type, $name, $deprecatedMessage)
68
    {
69 10
        $node = $node->$type($name);
70
71 10
        if (Kernel::VERSION_ID >= 50100) {
72 10
            $node = $node->setDeprecated('mmucklo/queue-bundle', '5.1', $deprecatedMessage);
73
        } elseif (Kernel::VERSION_ID >= 30400) {
74
            $node = $node->setDeprecated($deprecatedMessage);
75
        }
76
77 10
        return $node->end();
78
    }
79
80 10
    protected function addTimings()
81
    {
82 10
        $treeBuilder = new TreeBuilder('timings');
83
84 10
        if (method_exists($treeBuilder, 'getRootNode')) {
85 10
            $rootNode = $treeBuilder->getRootNode();
86
        } else {
87
            // BC layer for symfony/config 4.1 and older
88
            $rootNode = $treeBuilder->root('timings');
89
        }
90
91
        $rootNode
92 10
            ->addDefaultsIfNotSet()
93 10
            ->children()
94 10
                ->booleanNode('record')
95 10
                    ->info('Set this to true to record timings (used on the Trends page)')
96 10
                    ->defaultFalse()
97 10
                ->end()
98 10
                ->floatNode('timezone_offset')
99 10
                    ->defaultValue(0)
100 10
                    ->info('Set this some integer offset from GMT in case your database is not storing things in the proper timezone and the dates look off on the Trends page')
101 10
                    ->max(24)
102 10
                    ->min(-24)
103 10
                ->end()
104 10
            ->end();
105
106 10
        return $rootNode;
107
    }
108
109 10
    protected function addSimpleScalar($rootName, $nodeName, $info, $defaultValue = 'default')
110
    {
111 10
        $treeBuilder = new TreeBuilder($rootName);
112
113 10
        if (method_exists($treeBuilder, 'getRootNode')) {
114 10
            $rootNode = $treeBuilder->getRootNode();
115
        } else {
116
            // BC layer for symfony/config 4.1 and older
117
            $rootNode = $treeBuilder->root($rootName);
118
        }
119
120
        $rootNode
121 10
            ->addDefaultsIfNotSet()
122 10
            ->children()
123 10
            ->scalarNode($nodeName)
124 10
            ->info($info)
125 10
            ->defaultValue($defaultValue)
126 10
            ->cannotBeEmpty()
127 10
            ->end()
128 10
            ->end();
129
130 10
        return $rootNode;
131
    }
132
133 10
    protected function addManager()
134
    {
135 10
        $treeBuilder = new TreeBuilder('manager');
136
137 10
        if (method_exists($treeBuilder, 'getRootNode')) {
138 10
            $rootNode = $treeBuilder->getRootNode();
139
        } else {
140
            // BC layer for symfony/config 4.1 and older
141
            $rootNode = $treeBuilder->root('manager');
142
        }
143
        $rootNode
144 10
            ->addDefaultsIfNotSet()
145 10
            ->children()
146 10
                ->scalarNode('job')
147 10
                    ->defaultValue('odm')
148 10
                    ->info('This can be [odm|orm|beanstalkd|rabbit_mq|redis|(your-own-custom-one)]')
149 10
                    ->cannotBeEmpty()
150 10
                ->end()
151 10
                ->scalarNode('run')->end()
152 10
                ->scalarNode('job_timing')->end()
153 10
            ->end();
154
155 10
        return $rootNode;
156
    }
157
158 10
    protected function addBeanstalkd()
159
    {
160 10
        $treeBuilder = new TreeBuilder('beanstalkd');
161
162 10
        if (method_exists($treeBuilder, 'getRootNode')) {
163 10
            $rootNode = $treeBuilder->getRootNode();
164
        } else {
165
            // BC layer for symfony/config 4.1 and older
166
            $rootNode = $treeBuilder->root('beanstalkd');
167
        }
168
169
        $rootNode
170 10
            ->children()
171 10
                ->scalarNode('host')->end()
172 10
                ->integerNode('port')
173 10
                    ->defaultValue(11300)
174 10
                ->end()
175 10
                ->scalarNode('tube')->end()
176 10
            ->end();
177
178 10
        return $rootNode;
179
    }
180
181 10
    protected function addRetry()
182
    {
183 10
        $treeBuilder = new TreeBuilder('retry');
184
185 10
        if (method_exists($treeBuilder, 'getRootNode')) {
186 10
            $rootNode = $treeBuilder->getRootNode();
187
        } else {
188
            // BC layer for symfony/config 4.1 and older
189
            $rootNode = $treeBuilder->root('retry');
190
        }
191
192
        $rootNode
193 10
            ->addDefaultsIfNotSet()
194 10
            ->children()
195 10
                ->arrayNode('max')
196 10
                    ->addDefaultsIfNotSet()
197 10
                    ->children()
198 10
                        ->integerNode('retries')
199 10
                            ->info('This the maximum total number of retries of any type.')
200 10
                            ->defaultValue(3)
201 10
                        ->end()
202 10
                        ->integerNode('failures')
203 10
                            ->info('This the maximum total number of failures before a job is marked as hitting the maximum failures.')
204 10
                            ->defaultValue(1)
205 10
                        ->end()
206 10
                        ->integerNode('exceptions')
207 10
                            ->info('This the maximum total number of exceptions before a job is marked as hitting the maximum exceptions.')
208 10
                            ->defaultValue(2)
209 10
                        ->end()
210 10
                        ->integerNode('stalls')
211 10
                            ->info('This the maximum total number of exceptions before a job is marked as hitting the maximum exceptions.')
212 10
                            ->defaultValue(2)
213 10
                        ->end()
214 10
                    ->end()
215 10
                ->end()
216 10
                ->arrayNode('auto')
217 10
                    ->addDefaultsIfNotSet()
218 10
                    ->children()
219 10
                        ->booleanNode('failure')
220 10
                            ->info('Instantly re-queue the job on failure.')
221 10
                            ->defaultTrue()
222 10
                        ->end()
223 10
                        ->booleanNode('exception')
224 10
                            ->info('Instantly re-queue the job on exception.')
225 10
                            ->defaultFalse()
226 10
                        ->end()
227 10
                    ->end()
228 10
                ->end()
229 10
            ->end();
230
231 10
        return $rootNode;
232
    }
233
234 10
    protected function addPriority()
235
    {
236 10
        $treeBuilder = new TreeBuilder('priority');
237
238 10
        if (method_exists($treeBuilder, 'getRootNode')) {
239 10
            $rootNode = $treeBuilder->getRootNode();
240
        } else {
241
            // BC layer for symfony/config 4.1 and older
242
            $rootNode = $treeBuilder->root('priority');
243
        }
244
        $rootNode
245 10
            ->addDefaultsIfNotSet()
246 10
            ->children()
247 10
                ->integerNode('max')
248 10
                    ->defaultValue(255)
249 10
                    ->info('Maximum priority value.')
250 10
                    ->min(1)
251 10
                ->end()
252 10
                ->enumNode('direction')
253 10
                    ->values([PriorityJobManager::PRIORITY_ASC, PriorityJobManager::PRIORITY_DESC])
254 10
                    ->info('Whether 1 is high priority or low prioirty.  '.PriorityJobManager::PRIORITY_ASC.' means 1 is low, '.PriorityJobManager::PRIORITY_DESC.' means 1 is high.')
255 10
                    ->defaultValue(PriorityJobManager::PRIORITY_DESC)
256 10
                ->end()
257 10
            ->end();
258
259 10
        return $rootNode;
260
    }
261
262 10
    protected function addClasses()
263
    {
264 10
        $treeBuilder = new TreeBuilder('class');
265
266 10
        if (method_exists($treeBuilder, 'getRootNode')) {
267 10
            $rootNode = $treeBuilder->getRootNode();
268
        } else {
269
            // BC layer for symfony/config 4.1 and older
270
            $rootNode = $treeBuilder->root('class');
271
        }
272
273
        $rootNode
274 10
            ->children()
275 10
                ->scalarNode('job')
276 10
                    ->info('If you want to override the Job class, put the class name here.')->end()
277 10
                ->scalarNode('job_archive')
278 10
                    ->info('If you want to override the JobArchive class, put the class name here.')->end()
279 10
                ->scalarNode('job_timing')
280 10
                    ->info('If you want to override the JobTiming class, put the class name here.')->end()
281 10
                ->scalarNode('run')
282 10
                    ->info('If you want to override the Run class, put the class name here.')->end()
283 10
                ->scalarNode('run_archive')
284 10
                    ->info('If you want to override the RunArchive class, put the class name here.')->end()
285 10
            ->end();
286
287 10
        return $rootNode;
288
    }
289
}
290