Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 77
Code Lines 70

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 77
rs 8.9342
cc 2
eloc 70
nc 1
nop 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 Mpclarkson\ResqueBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * This is the class that validates and merges configuration from your app/config files
10
 *
11
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12
 */
13
class Configuration implements ConfigurationInterface
14
{
15
    /**
16
     * {@inheritDoc}
17
     */
18
    public function getConfigTreeBuilder()
19
    {
20
        $treeBuilder = new TreeBuilder();
21
        $rootNode = $treeBuilder->root('resque');
22
23
        $rootNode
24
            ->addDefaultsIfNotSet()
25
            ->children()
26
                ->scalarNode('vendor_dir')
27
                    ->defaultValue('%kernel.root_dir%/../vendor')
28
                    ->cannotBeEmpty()
29
                    ->info('Set the vendor dir')
30
                ->end()
31
                ->scalarNode('app_include')
32
                    ->defaultValue('%kernel.root_dir%/../var/bootstrap.php.cache')
33
                    ->cannotBeEmpty()
34
                    ->info('Set the APP_INCLUDE for php-resque')
35
                ->end()
36
                ->scalarNode('prefix')
37
                    ->defaultNull()
38
                    ->end()
39
                ->scalarNode('class')
40
                    ->defaultValue('Mpclarkson\ResqueBundle\Resque')
41
                    ->cannotBeEmpty()
42
                    ->info('Set the resque class dir')
43
                ->end()
44
                ->arrayNode('auto_retry')
45
                    ->beforeNormalization()
46
                        ->ifArray()
47
                        ->then(function($var) {
48
                            if (array_key_exists(0, $var)) {
49
                                return [$var];
50
                            }
51
                            return $var;
52
                        })
53
                    ->end()
54
                    ->prototype('array')
55
                        ->prototype('scalar')->end()
56
                    ->end()
57
                    ->info('Set auto retry strategy')
58
                ->end()
59
                ->arrayNode('redis')
60
                    ->info('Redis configuration')
61
                    ->addDefaultsIfNotSet()
62
                    ->children()
63
                        ->scalarNode('host')
64
                            ->defaultValue('localhost')
65
                            ->cannotBeEmpty()
66
                            ->info('The redis hostname')
67
                        ->end()
68
                        ->scalarNode('port')
69
                            ->defaultValue(6379)
70
                            ->cannotBeEmpty()
71
                            ->info('The redis port')
72
                        ->end()
73
                        ->scalarNode('database')
74
                            ->defaultValue(0)
75
                            ->info('The redis database')
76
                        ->end()
77
                    ->end()
78
                ->end()
79
                ->arrayNode('worker')
80
                    ->info('Worker Server configuration')
81
                    ->addDefaultsIfNotSet()
82
                    ->children()
83
                        ->scalarNode('root_dir')
84
                            ->defaultValue('%kernel.root_dir%')
85
                            ->cannotBeEmpty()
86
                            ->info('The root dir of worker registered app')
87
                        ->end()
88
                    ->end()
89
                ->end()
90
            ->end()
91
        ;
92
93
        return $treeBuilder;
94
    }
95
}
96