Completed
Push — master ( 6031ad...3550b4 )
by Jeroen
07:05
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 104
Code Lines 81

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 72
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 104
ccs 72
cts 74
cp 0.973
rs 8.2857
cc 1
eloc 81
nc 1
nop 0
crap 1

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 TreeHouse\IoBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
class Configuration implements ConfigurationInterface
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13 2
    public function getConfigTreeBuilder()
14
    {
15 2
        $treeBuilder = new TreeBuilder();
16 2
        $rootNode = $treeBuilder->root('tree_house_io')->children();
17
18
        $rootNode
19 2
            ->scalarNode('data_dir')
20 2
            ->defaultValue('%kernel.root_dir%/var/data')
21
        ;
22
23
        $rootNode
24 2
            ->scalarNode('origin_manager_id')
25 2
            ->isRequired()
26
        ;
27
28
        $rootNode
29 2
            ->scalarNode('source_manager_id')
30 2
            ->isRequired()
31
        ;
32
33
        $rootNode
34 2
            ->scalarNode('source_processor_id')
35 2
            ->defaultValue('tree_house.io.source.processor.delegating')
36
        ;
37
38
        $rootNode
39 2
            ->scalarNode('source_cleaner_id')
40 2
            ->defaultValue('tree_house.io.source.cleaner.delegating')
41
        ;
42
43
        $rootNode
44 2
            ->arrayNode('import')
45 2
                ->addDefaultsIfNotSet()
46 2
                ->children()
47 2
                    ->scalarNode('dir')
48 2
                        ->defaultValue('%tree_house.io.data_dir%/import')
49 2
                    ->end()
50
51 2
                    ->arrayNode('import_part')
52 2
                        ->children()
53 2
                            ->scalarNode('time_to_run')
54 2
                                ->defaultValue(1200)
55 2
                            ->end()
56 2
                        ->end()
57 2
                    ->end()
58
59 2
                    ->arrayNode('item_logger')
60 2
                        ->beforeNormalization()
61 2
                            ->ifString()
62
                            ->then(function ($type) {
63
                                return ['type' => $type];
64 2
                            })
65 2
                        ->end()
66 2
                        ->children()
67 2
                            ->enumNode('type')
68 2
                                ->values(['array', 'redis', 'predis'])
69 2
                            ->end()
70 2
                            ->scalarNode('client')
71 2
                            ->end()
72 2
                            ->scalarNode('service')
73 2
                            ->end()
74 2
                        ->end()
75 2
                    ->end()
76 2
                    ->arrayNode('reader')
77 2
                        ->addDefaultsIfNotSet()
78 2
                        ->children()
79 2
                            ->arrayNode('multipart')
80 2
                                ->addDefaultsIfNotSet()
81 2
                                ->children()
82 2
                                    ->scalarNode('default_part_size')
83 2
                                        ->defaultValue(1000)
84
        ;
85
86
        $rootNode
87 2
            ->arrayNode('export')
88 2
                ->addDefaultsIfNotSet()
89 2
                ->children()
90 2
                    ->scalarNode('dir')
91 2
                        ->defaultValue('%tree_house.io.data_dir%/export')
92 2
                    ->end()
93 2
                    ->scalarNode('cache_dir')
94 2
                        ->info('Will store cache files for individual items')
95 2
                        ->defaultValue('%tree_house.io.export.dir%/cache')
96 2
                    ->end()
97 2
                    ->scalarNode('output_dir')
98 2
                        ->info('Will store final export file for all exported feeds')
99 2
                        ->defaultValue('%tree_house.io.export.dir%/generated')
100 2
                    ->end()
101 2
                ->end()
102 2
            ->end()
103
        ;
104
105
        $rootNode
106 2
            ->arrayNode('bridges')
107 2
            ->prototype('scalar')
108 2
            ->validate()
109 2
            ->ifTrue(function ($bridge) {
110
                return !in_array($bridge, ['WorkerBundle']);
111 2
            })
112 2
            ->thenInvalid('Invalid bridge %s. Valid bridge values are: "WorkerBundle"')
113
        ;
114
115 2
        return $treeBuilder;
116
    }
117
}
118