Passed
Push — master ( 3d3a35...263c14 )
by Matthew
08:06
created

Configuration::addPredisArgs()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 34
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 5.009

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 26
cts 28
cp 0.9286
rs 8.439
c 0
b 0
f 0
cc 5
eloc 28
nc 1
nop 0
crap 5.009
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 9
    public function getConfigTreeBuilder()
21
    {
22 9
        $treeBuilder = new TreeBuilder();
23 9
        $rootNode = $treeBuilder->root('dtc_queue');
24
25
        $node = $rootNode
26 9
            ->children()
27 9
                ->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'))
28 9
                ->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'))
29 9
                ->append($this->addManager())
30 9
                ->append($this->addTimings())
31 9
                ->append($this->addBeanstalkd())
32 9
                ->append($this->addRabbitMq())
33 9
                ->append($this->addRedis())
34 9
                ->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'))
35 9
                ->append($this->addClasses())
36 9
                ->append($this->addPriority())
37 9
                ->append($this->addRetry());
38
39 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'document_manager', 'The "%node% option is deprecated, Use "odm: { document_manager: ... }" instead.');
40 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'entity_manager', 'The "%node% option is deprecated, Use "orm: { entity_manager: ... }" instead.');
41 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'default_manager', 'The "%node% option is deprecated, Use "manager: { job: ... }" instead.');
42 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'run_manager', 'The "%node% option is deprecated, Use "manager: { run: ... }" instead.');
43 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'job_timing_manager', 'The "%node% option is deprecated, Use "manager: { job_timing: ... }" instead.');
44 9
        $node = $this->setDeprecatedNode($node, 'booleanNode', 'record_timings', 'The "%node% option is deprecated, Use "timings: { record: ... }" instead.');
45 9
        $node = $this->setDeprecatedNode($node, 'floatNode', 'record_timings_timezone_offset', 'The "%node% option is deprecated, Use "record: { timezone_offset: ... }" instead.');
46 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job', 'The "%node% option is deprecated, Use "class: { job: ... }" instead.');
47 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job_archive', 'The "%node% option is deprecated, Use "class: { job_archive: ... }" instead.');
48 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_run', 'The "%node% option is deprecated, Use "class: { run: ... }" instead.');
49 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_run_archive', 'The "%node% option is deprecated, Use "class: { run_archive: ... }" instead.');
50 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'class_job_timing', 'The "%node% option is deprecated, Use "class: { job_timing: ... }" instead.');
51 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'priority_max', 'The "%node% option is deprecated, Use "priority: { max: ... }" instead.');
52 9
        $node = $this->setDeprecatedNode($node, 'scalarNode', 'priority_direction', 'The "%node% option is deprecated, Use "priority: { direction: ... }" instead.');
53 9
        $node->end();
54
55 9
        return $treeBuilder;
56
    }
57
58 9
    public function setDeprecatedNode($node, $type, $name, $deprecatedMessage)
59
    {
60 9
        $node = $node->$type($name);
61
62 9
        if (Kernel::VERSION_ID >= 30400) {
63 9
            $node = $node->setDeprecated($deprecatedMessage);
64
        }
65
66 9
        return $node->end();
67
    }
68
69 9
    protected function addTimings()
70
    {
71 9
        $treeBuilder = new TreeBuilder();
72 9
        $rootNode = $treeBuilder->root('timings');
73
        $rootNode
74 9
            ->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

74
            ->/** @scrutinizer ignore-call */ 
75
              addDefaultsIfNotSet()
Loading history...
75 9
            ->children()
76 9
                ->booleanNode('record')
77 9
                    ->info('Set this to true to record timings (used on the Trends page)')
78 9
                    ->defaultFalse()
79 9
                ->end()
80 9
                ->floatNode('timezone_offset')
81 9
                    ->defaultValue(0)
82 9
                    ->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')
83 9
                    ->max(24)
84 9
                    ->min(-24)
85 9
                ->end()
86 9
            ->end();
87
88 9
        return $rootNode;
89
    }
90
91 9
    protected function addSimpleScalar($rootName, $nodeName, $info, $defaultValue = 'default')
92
    {
93 9
        $treeBuilder = new TreeBuilder();
94 9
        $rootNode = $treeBuilder->root($rootName);
95
        $rootNode
96 9
            ->addDefaultsIfNotSet()
97 9
            ->children()
98 9
            ->scalarNode($nodeName)
99 9
            ->info($info)
100 9
            ->defaultValue($defaultValue)
101 9
            ->cannotBeEmpty()
102 9
            ->end()
103 9
            ->end();
104
105 9
        return $rootNode;
106
    }
107
108 9
    protected function addManager()
109
    {
110 9
        $treeBuilder = new TreeBuilder();
111 9
        $rootNode = $treeBuilder->root('manager');
112
        $rootNode
113 9
            ->addDefaultsIfNotSet()
114 9
            ->children()
115 9
                ->scalarNode('job')
116 9
                    ->defaultValue('odm')
117 9
                    ->info('This can be [odm|orm|beanstalkd|rabbit_mq|redis|(your-own-custom-one)]')
118 9
                    ->cannotBeEmpty()
119 9
                ->end()
120 9
                ->scalarNode('run')->end()
121 9
                ->scalarNode('job_timing')->end()
122 9
            ->end();
123
124 9
        return $rootNode;
125
    }
126
127 9
    protected function addBeanstalkd()
128
    {
129 9
        $treeBuilder = new TreeBuilder();
130 9
        $rootNode = $treeBuilder->root('beanstalkd');
131
        $rootNode
132 9
            ->children()
133 9
                ->scalarNode('host')->end()
134 9
                ->scalarNode('tube')->end()
135 9
            ->end();
136
137 9
        return $rootNode;
138
    }
139
140 9
    protected function addRetry()
141
    {
142 9
        $treeBuilder = new TreeBuilder();
143 9
        $rootNode = $treeBuilder->root('retry');
144
        $rootNode
145 9
            ->addDefaultsIfNotSet()
146 9
            ->children()
147 9
                ->arrayNode('max')
148 9
                    ->addDefaultsIfNotSet()
149 9
                    ->children()
150 9
                        ->integerNode('retries')
151 9
                            ->info('This the maximum total number of retries of any type.')
152 9
                            ->defaultValue(3)
153 9
                        ->end()
154 9
                        ->integerNode('failures')
155 9
                            ->info('This the maximum total number of failures before a job is marked as hitting the maximum failures.')
156 9
                            ->defaultValue(1)
157 9
                        ->end()
158 9
                        ->integerNode('exceptions')
159 9
                            ->info('This the maximum total number of exceptions before a job is marked as hitting the maximum exceptions.')
160 9
                            ->defaultValue(2)
161 9
                        ->end()
162 9
                        ->integerNode('stalls')
163 9
                            ->info('This the maximum total number of exceptions before a job is marked as hitting the maximum exceptions.')
164 9
                            ->defaultValue(2)
165 9
                        ->end()
166 9
                    ->end()
167 9
                ->end()
168 9
                ->arrayNode('auto')
169 9
                    ->addDefaultsIfNotSet()
170 9
                    ->children()
171 9
                        ->booleanNode('failure')
172 9
                            ->info('Instantly re-queue the job on failure.')
173 9
                            ->defaultTrue()
174 9
                        ->end()
175 9
                        ->booleanNode('exception')
176 9
                            ->info('Instantly re-queue the job on exception.')
177 9
                            ->defaultFalse()
178 9
                        ->end()
179 9
                    ->end()
180 9
                ->end()
181 9
            ->end();
182
183 9
        return $rootNode;
184
    }
185
186 9
    protected function addPriority()
187
    {
188 9
        $treeBuilder = new TreeBuilder();
189 9
        $rootNode = $treeBuilder->root('priority');
190
        $rootNode
191 9
            ->addDefaultsIfNotSet()
192 9
            ->children()
193 9
                ->integerNode('max')
194 9
                    ->defaultValue(255)
195 9
                    ->info('Maximum priority value.')
196 9
                    ->min(1)
197 9
                ->end()
198 9
                ->enumNode('direction')
199 9
                    ->values([PriorityJobManager::PRIORITY_ASC, PriorityJobManager::PRIORITY_DESC])
200 9
                    ->info('Whether 1 is high priority or low prioirty.  '.PriorityJobManager::PRIORITY_ASC.' means 1 is low, '.PriorityJobManager::PRIORITY_DESC.' means 1 is high.')
201 9
                    ->defaultValue(PriorityJobManager::PRIORITY_DESC)
202 9
                ->end()
203 9
            ->end();
204
205 9
        return $rootNode;
206
    }
207
208 9
    protected function addClasses()
209
    {
210 9
        $treeBuilder = new TreeBuilder();
211 9
        $rootNode = $treeBuilder->root('class');
212
        $rootNode
213 9
            ->children()
214 9
                ->scalarNode('job')
215 9
                    ->info('If you want to override the Job class, put the class name here.')->end()
216 9
                ->scalarNode('job_archive')
217 9
                    ->info('If you want to override the JobArchive class, put the class name here.')->end()
218 9
                ->scalarNode('job_timing')
219 9
                    ->info('If you want to override the JobTiming class, put the class name here.')->end()
220 9
                ->scalarNode('run')
221 9
                    ->info('If you want to override the Run class, put the class name here.')->end()
222 9
                ->scalarNode('run_archive')
223 9
                    ->info('If you want to override the RunArchive class, put the class name here.')->end()
224 9
            ->end();
225
226 9
        return $rootNode;
227
    }
228
}
229