Passed
Push — master ( fa4594...c101ff )
by Matthew
07:38
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 45
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 36
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 38
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 45
ccs 36
cts 37
cp 0.973
crap 2
rs 9.312
1
<?php
2
3
namespace Dtc\QueueBundle\DependencyInjection;
4
5
use Dtc\QueueBundle\Manager\PriorityJobManager;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
use Symfony\Component\HttpKernel\Kernel;
9
10
class Configuration implements ConfigurationInterface
11
{
12
    use RedisConfiguration;
13
    use RabbitMQConfiguration;
14
15
    /**
16
     * Generates the configuration tree.
17
     *
18
     * @return TreeBuilder
19
     */
20 10
    public function getConfigTreeBuilder()
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');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

28
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('dtc_queue');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
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 >= 30400) {
72 10
            $node = $node->setDeprecated($deprecatedMessage);
73
        }
74
75 10
        return $node->end();
76
    }
77
78 10
    protected function addTimings()
79
    {
80 10
        $treeBuilder = new TreeBuilder('timings');
81
82 10
        if (method_exists($treeBuilder, 'getRootNode')) {
83 10
            $rootNode = $treeBuilder->getRootNode();
84
        } else {
85
            // BC layer for symfony/config 4.1 and older
86
            $rootNode = $treeBuilder->root('timings');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

86
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('timings');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
87
        }
88
89
        $rootNode
90 10
            ->addDefaultsIfNotSet()
0 ignored issues
show
Bug introduced by
The method addDefaultsIfNotSet() 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

90
            ->/** @scrutinizer ignore-call */ 
91
              addDefaultsIfNotSet()
Loading history...
91 10
            ->children()
92 10
                ->booleanNode('record')
93 10
                    ->info('Set this to true to record timings (used on the Trends page)')
94 10
                    ->defaultFalse()
95 10
                ->end()
96 10
                ->floatNode('timezone_offset')
97 10
                    ->defaultValue(0)
98 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')
99 10
                    ->max(24)
100 10
                    ->min(-24)
101 10
                ->end()
102 10
            ->end();
103
104 10
        return $rootNode;
105
    }
106
107 10
    protected function addSimpleScalar($rootName, $nodeName, $info, $defaultValue = 'default')
108
    {
109 10
        $treeBuilder = new TreeBuilder($rootName);
110
111 10
        if (method_exists($treeBuilder, 'getRootNode')) {
112 10
            $rootNode = $treeBuilder->getRootNode();
113
        } else {
114
            // BC layer for symfony/config 4.1 and older
115
            $rootNode = $treeBuilder->root($rootName);
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

115
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root($rootName);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
116
        }
117
118
        $rootNode
119 10
            ->addDefaultsIfNotSet()
120 10
            ->children()
121 10
            ->scalarNode($nodeName)
122 10
            ->info($info)
123 10
            ->defaultValue($defaultValue)
124 10
            ->cannotBeEmpty()
125 10
            ->end()
126 10
            ->end();
127
128 10
        return $rootNode;
129
    }
130
131 10
    protected function addManager()
132
    {
133 10
        $treeBuilder = new TreeBuilder('manager');
134
135 10
        if (method_exists($treeBuilder, 'getRootNode')) {
136 10
            $rootNode = $treeBuilder->getRootNode();
137
        } else {
138
            // BC layer for symfony/config 4.1 and older
139
            $rootNode = $treeBuilder->root('manager');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

139
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('manager');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
140
        }
141
        $rootNode
142 10
            ->addDefaultsIfNotSet()
143 10
            ->children()
144 10
                ->scalarNode('job')
145 10
                    ->defaultValue('odm')
146 10
                    ->info('This can be [odm|orm|beanstalkd|rabbit_mq|redis|(your-own-custom-one)]')
147 10
                    ->cannotBeEmpty()
148 10
                ->end()
149 10
                ->scalarNode('run')->end()
150 10
                ->scalarNode('job_timing')->end()
151 10
            ->end();
152
153 10
        return $rootNode;
154
    }
155
156 10
    protected function addBeanstalkd()
157
    {
158 10
        $treeBuilder = new TreeBuilder('beanstalkd');
159
160 10
        if (method_exists($treeBuilder, 'getRootNode')) {
161 10
            $rootNode = $treeBuilder->getRootNode();
162
        } else {
163
            // BC layer for symfony/config 4.1 and older
164
            $rootNode = $treeBuilder->root('beanstalkd');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

164
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('beanstalkd');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
165
        }
166
167
        $rootNode
168 10
            ->children()
169 10
                ->scalarNode('host')->end()
170 10
                ->scalarNode('tube')->end()
171 10
            ->end();
172
173 10
        return $rootNode;
174
    }
175
176 10
    protected function addRetry()
177
    {
178 10
        $treeBuilder = new TreeBuilder('retry');
179
180 10
        if (method_exists($treeBuilder, 'getRootNode')) {
181 10
            $rootNode = $treeBuilder->getRootNode();
182
        } else {
183
            // BC layer for symfony/config 4.1 and older
184
            $rootNode = $treeBuilder->root('retry');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

184
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('retry');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
185
        }
186
187
        $rootNode
188 10
            ->addDefaultsIfNotSet()
189 10
            ->children()
190 10
                ->arrayNode('max')
191 10
                    ->addDefaultsIfNotSet()
192 10
                    ->children()
193 10
                        ->integerNode('retries')
194 10
                            ->info('This the maximum total number of retries of any type.')
195 10
                            ->defaultValue(3)
196 10
                        ->end()
197 10
                        ->integerNode('failures')
198 10
                            ->info('This the maximum total number of failures before a job is marked as hitting the maximum failures.')
199 10
                            ->defaultValue(1)
200 10
                        ->end()
201 10
                        ->integerNode('exceptions')
202 10
                            ->info('This the maximum total number of exceptions before a job is marked as hitting the maximum exceptions.')
203 10
                            ->defaultValue(2)
204 10
                        ->end()
205 10
                        ->integerNode('stalls')
206 10
                            ->info('This the maximum total number of exceptions before a job is marked as hitting the maximum exceptions.')
207 10
                            ->defaultValue(2)
208 10
                        ->end()
209 10
                    ->end()
210 10
                ->end()
211 10
                ->arrayNode('auto')
212 10
                    ->addDefaultsIfNotSet()
213 10
                    ->children()
214 10
                        ->booleanNode('failure')
215 10
                            ->info('Instantly re-queue the job on failure.')
216 10
                            ->defaultTrue()
217 10
                        ->end()
218 10
                        ->booleanNode('exception')
219 10
                            ->info('Instantly re-queue the job on exception.')
220 10
                            ->defaultFalse()
221 10
                        ->end()
222 10
                    ->end()
223 10
                ->end()
224 10
            ->end();
225
226 10
        return $rootNode;
227
    }
228
229 10
    protected function addPriority()
230
    {
231 10
        $treeBuilder = new TreeBuilder('priority');
232
233 10
        if (method_exists($treeBuilder, 'getRootNode')) {
234 10
            $rootNode = $treeBuilder->getRootNode();
235
        } else {
236
            // BC layer for symfony/config 4.1 and older
237
            $rootNode = $treeBuilder->root('priority');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

237
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('priority');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
238
        }
239
        $rootNode
240 10
            ->addDefaultsIfNotSet()
241 10
            ->children()
242 10
                ->integerNode('max')
243 10
                    ->defaultValue(255)
244 10
                    ->info('Maximum priority value.')
245 10
                    ->min(1)
246 10
                ->end()
247 10
                ->enumNode('direction')
248 10
                    ->values([PriorityJobManager::PRIORITY_ASC, PriorityJobManager::PRIORITY_DESC])
249 10
                    ->info('Whether 1 is high priority or low prioirty.  '.PriorityJobManager::PRIORITY_ASC.' means 1 is low, '.PriorityJobManager::PRIORITY_DESC.' means 1 is high.')
250 10
                    ->defaultValue(PriorityJobManager::PRIORITY_DESC)
251 10
                ->end()
252 10
            ->end();
253
254 10
        return $rootNode;
255
    }
256
257 10
    protected function addClasses()
258
    {
259 10
        $treeBuilder = new TreeBuilder('class');
260
261 10
        if (method_exists($treeBuilder, 'getRootNode')) {
262 10
            $rootNode = $treeBuilder->getRootNode();
263
        } else {
264
            // BC layer for symfony/config 4.1 and older
265
            $rootNode = $treeBuilder->root('class');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

265
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('class');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
266
        }
267
268
        $rootNode
269 10
            ->children()
270 10
                ->scalarNode('job')
271 10
                    ->info('If you want to override the Job class, put the class name here.')->end()
272 10
                ->scalarNode('job_archive')
273 10
                    ->info('If you want to override the JobArchive class, put the class name here.')->end()
274 10
                ->scalarNode('job_timing')
275 10
                    ->info('If you want to override the JobTiming class, put the class name here.')->end()
276 10
                ->scalarNode('run')
277 10
                    ->info('If you want to override the Run class, put the class name here.')->end()
278 10
                ->scalarNode('run_archive')
279 10
                    ->info('If you want to override the RunArchive class, put the class name here.')->end()
280 10
            ->end();
281
282 10
        return $rootNode;
283
    }
284
}
285