Configuration::getConfigTreeBuilder()   C
last analyzed

Complexity

Conditions 8
Paths 1

Size

Total Lines 219

Duplication

Lines 2
Ratio 0.91 %

Code Coverage

Tests 196
CRAP Score 8

Importance

Changes 0
Metric Value
dl 2
loc 219
ccs 196
cts 196
cp 1
rs 6.7555
c 0
b 0
f 0
cc 8
nc 1
nop 0
crap 8

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 Mathielen\ImportEngineBundle\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
    public function getConfigTreeBuilder()
11
    {
12 11
        $storageTypes = array('callable', 'service', 'array', 'doctrine', 'file');
13 11
        $providerTypes = array('file', 'directory', 'upload', 'doctrine', 'service', 'dbal');
14 11
        $fileFormats = array('csv', 'excel', 'xml', 'yaml');
15
16 11
        $treeBuilder = new TreeBuilder();
0 ignored issues
show
Bug introduced by
The call to TreeBuilder::__construct() misses a required argument $name.

This check looks for function calls that miss required arguments.

Loading history...
17
        $treeBuilder
0 ignored issues
show
Bug introduced by
The method root() does not seem to exist on object<Symfony\Component...on\Builder\TreeBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18 11
            ->root('mathielen_import_engine')
19 11
            ->fixXmlConfig('importer')
20 11
                ->children()
21 11
                    ->arrayNode('storageprovider')
22 11
                        ->useAttributeAsKey('name')
23 11
                        ->prototype('array')
24 11
                            ->fixXmlConfig('service') //allows <service> instead of <services>
25 11
                            ->fixXmlConfig('query', 'queries') //allows <query> instead of <queries>
26 11
                            ->children()
27 11
                                ->enumNode('type')
28 11
                                    ->values($providerTypes)
29 11
                                ->end()
30 11
                                ->scalarNode('uri')->end()                      //file
31 11
                                ->scalarNode('connection_factory')->end()       //dbal & doctrine
32 11
                                ->arrayNode('services')
33 11
                                    ->useAttributeAsKey('name')
34 11
                                    ->prototype('array')
35 11
                                        ->fixXmlConfig('method') //allows <method> instead of <methods>
36 11
                                        ->beforeNormalization()
37 11
                                            ->ifArray()
38
                                            ->then(function ($v) { return isset($v['methods']) || isset($v['method']) ? $v : array('methods' => $v); })
39 11
                                        ->end()
40 11
                                        ->children()
41 11
                                            ->arrayNode('methods')
42 11
                                                ->prototype('scalar')->end()
43 11
                                            ->end()
44 11
                                        ->end()
45 11
                                    ->end()
46 11
                                ->end()
47 11
                                ->arrayNode('queries')                          //dbal & doctrine
48 11
                                    ->beforeNormalization()
49 11
                                        ->ifString()
50
                                        ->then(function ($v) { return [$v]; })
51 11
                                    ->end()
52 11
                                    ->useAttributeAsKey('name')
53 11
                                    ->prototype('scalar')->end()
54 11
                                ->end()
55 11
                            ->end()
56 11
                        ->end()
57 11
                    ->end()
58 11
                    ->arrayNode('importers')
59 11
                        ->requiresAtLeastOneElement()
60 11
                        ->useAttributeAsKey('name')
61 11
                        ->prototype('array')
62 11
                            ->fixXmlConfig('mapping') //allows <mapping> instead of <mappings>
63 11
                            ->children()
64 11
                                ->arrayNode('context')
65 11
                                    ->beforeNormalization()
66 11
                                        ->ifString()
67
                                        ->then(function ($v) { return array($v); })
68 11
                                    ->end()
69 11
                                    ->prototype('variable')->end()
70 11
                                ->end()
71
72 11
                                ->arrayNode('preconditions')
73 11
                                    ->fixXmlConfig('field')  //allows <field> instead of <fields>
74 11
                                    ->children()
75 11
                                        ->arrayNode('format')
76 11
                                            ->beforeNormalization()
77 11
                                                ->ifString()
78
                                                ->then(function ($v) { return array($v); })
79 11
                                            ->end()
80 11
                                            ->prototype('enum')
81 11
                                                ->values($fileFormats)
82 11
                                            ->end()
83 11
                                        ->end()
84 11
                                        ->integerNode('fieldcount')->min(0)->end()
85 11
                                        ->arrayNode('filename')
86 11
                                            ->beforeNormalization()
87 11
                                                ->ifString()
88
                                                ->then(function ($v) { return array($v); })
89 11
                                            ->end()
90 11
                                            ->prototype('scalar')->end()
91 11
                                        ->end()
92 11
                                        ->arrayNode('fieldset')
93 11
                                            ->prototype('scalar')->end()
94 11
                                        ->end()
95 11
                                        ->arrayNode('fields')
96 11
                                            ->prototype('scalar')->end()
97 11
                                        ->end()
98 11
                                    ->end()
99 11
                                ->end()
100
101 11
                                ->arrayNode('object_factory')
102 11
                                    ->children()
103 11
                                        ->enumNode('type')
104 11
                                            ->defaultValue('default')
105 11
                                            ->values(array('default', 'jms_serializer'))
106 11
                                        ->end()
107 11
                                        ->scalarNode('class')
108 11
                                        ->end()
109 11
                                    ->end()
110 11
                                ->end()
111
112 11
                                ->arrayNode('filters')
113 11
                                    ->prototype('scalar')->end()
114 11
                                ->end()
115
116 11
                                ->arrayNode('mappings')
117 11
                                    ->normalizeKeys(false) //do not change - to _ with field names
118 11
                                    ->useAttributeAsKey('from')
119 11
                                    ->prototype('array')
120 11
                                        ->beforeNormalization()
121 11
                                            ->ifString()
122
                                            ->then(function ($v) { return array('to' => $v); })
123 11
                                        ->end()
124 11
                                        ->children()
125 11
                                            ->scalarNode('to')->end()
126 11
                                            ->scalarNode('converter')->end()
127 11
                                        ->end()
128 11
                                    ->end()
129 11
                                ->end()
130
131 11
                                ->arrayNode('source')
132 11
                                    ->children()
133 11
                                        ->enumNode('type')
134 11
                                            ->values($storageTypes)
135 11
                                        ->end()
136 11
                                        ->scalarNode('uri')->end()
137 11
                                        ->arrayNode('format')            //file
138 11
                                            ->fixXmlConfig('argument')
139 11
                                            ->beforeNormalization()
140 11
                                                ->ifString()
141
                                                ->then(function ($v) { return array('type' => $v); })
142 11
                                            ->end()
143 11
                                            ->children()
144 11
                                                ->scalarNode('type')->isRequired()->end()
145 11
                                                    ->arrayNode('arguments')
146 11
                                                    ->prototype('scalar')->end()
147 11
                                                ->end()
148 11
                                            ->end()
149 11
                                        ->end()
150 11
                                        ->scalarNode('service')->end()
151 11
                                        ->scalarNode('method')->end()
152 11
                                    ->end()
153 11
                                ->end()
154
155 11
                                ->arrayNode('validation')
156 11
                                    ->children()
157 11
                                        ->arrayNode('options')
158 11
                                            ->children()
159 11
                                                ->booleanNode('allowExtraFields')->end()
160 11
                                                ->booleanNode('allowMissingFields')->end()
161 11
                                            ->end()
162 11
                                        ->end()
163 11
                                        ->arrayNode('source')
164 11
                                            ->fixXmlConfig('constraint') //allows <constraint> instead of <constraints>
165 11
                                            ->beforeNormalization()
166 11
                                                ->ifArray()
167 View Code Duplication
                                                ->then(function ($v) { return isset($v['constraint']) || isset($v['constraints']) ? $v : array('constraints' => $v); })
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
168 11
                                            ->end()
169 11
                                            ->children()
170 11
                                                ->arrayNode('constraints')
171 11
                                                    ->useAttributeAsKey('field')
172 11
                                                    ->prototype('scalar')->end()
173 11
                                                ->end()
174 11
                                            ->end()
175 11
                                        ->end()
176 11
                                        ->arrayNode('target')
177 11
                                            ->fixXmlConfig('constraint') //allows <constraint> instead of <constraints>
178 11
                                            ->beforeNormalization()
179 11
                                                ->ifArray()
180 View Code Duplication
                                                ->then(function ($v) { return isset($v['constraint']) || isset($v['constraints']) ? $v : array('constraints' => $v); })
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
181 11
                                            ->end()
182 11
                                            ->children()
183 11
                                                ->arrayNode('constraints')
184 11
                                                    ->useAttributeAsKey('field')
185 11
                                                    ->prototype('scalar')->end()
186 11
                                                ->end()
187 11
                                            ->end()
188 11
                                        ->end()
189 11
                                    ->end()
190 11
                                ->end()
191
192 11
                                ->arrayNode('target')
193 11
                                    ->isRequired()
194 11
                                    ->beforeNormalization()
195 11
                                        ->always()
196
                                        ->then(function ($v) { return !isset($v['type']) ? ['type' => 'callable', 'callable' => $v] : $v; })
197 11
                                    ->end()
198 11
                                    ->children()
199 11
                                        ->enumNode('type')
200 11
                                            ->values($storageTypes)
201 11
                                        ->end()
202 11
                                        ->arrayNode('format')            //file
203 11
                                            ->fixXmlConfig('argument')
204 11
                                            ->beforeNormalization()
205 11
                                                ->ifString()
206
                                                ->then(function ($v) { return ['type' => $v]; })
207 11
                                            ->end()
208 11
                                            ->children()
209 11
                                                ->scalarNode('type')->isRequired()->end()
210 11
                                                ->arrayNode('arguments')
211 11
                                                    ->prototype('scalar')->end()
212 11
                                                ->end()
213 11
                                            ->end()
214 11
                                        ->end()
215 11
                                        ->scalarNode('uri')->end()      //file
216 11
                                        ->variableNode('callable')->end()  //callable
217 11
                                        ->variableNode('service')->end()  //service
218 11
                                        ->variableNode('method')->end()  //service
219 11
                                        ->scalarNode('entity')->end()   //doctrine
220 11
                                    ->end()
221 11
                                ->end()
222 11
                            ->end()
223 11
                        ->end()
224 11
                    ->end()
225 11
                ->end();
226
227 11
        return $treeBuilder;
228
    }
229
}
230