Completed
Push — develop ( bd5627...a32047 )
by Jens
02:58
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 102
Code Lines 89

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 48
CRAP Score 4

Importance

Changes 6
Bugs 1 Features 3
Metric Value
c 6
b 1
f 3
dl 0
loc 102
ccs 48
cts 48
cp 1
rs 8.1935
cc 4
eloc 89
nc 1
nop 0
crap 4

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
 * @author @jayS-de <[email protected]>
4
 */
5
6
7
namespace JaySDe\HandlebarsBundle\DependencyInjection;
8
9
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
10
use Symfony\Component\Config\Definition\ConfigurationInterface;
11
12
class Configuration implements ConfigurationInterface
13
{
14 12
    public function getConfigTreeBuilder()
15
    {
16
        $flags = array(
17 12
            'FLAG_ERROR_LOG',
18
            'FLAG_ERROR_EXCEPTION',
19
            'FLAG_JSTRUE',
20
            'FLAG_JSOBJECT',
21
            'FLAG_JSLENGTH',
22
            'FLAG_THIS',
23
            'FLAG_PARENT',
24
            'FLAG_HBESCAPE',
25
            'FLAG_ADVARNAME',
26
            'FLAG_SPACECTL',
27
            'FLAG_NAMEDARG',
28
            'FLAG_SPVARS',
29
            'FLAG_PREVENTINDENT',
30
            'FLAG_SLASH',
31
            'FLAG_ELSE',
32
            'FLAG_RAWBLOCK',
33
            'FLAG_HANDLEBARSLAMBDA',
34
            'FLAG_PARTIALNEWCONTEXT',
35
            'FLAG_IGNORESTANDALONE',
36
            'FLAG_STRINGPARAMS',
37
            'FLAG_KNOWNHELPERSONLY',
38
            'FLAG_STANDALONEPHP',
39
            'FLAG_EXTHELPER',
40
            'FLAG_ECHO',
41
            'FLAG_PROPERTY',
42
            'FLAG_METHOD',
43
            'FLAG_RUNTIMEPARTIAL',
44
            'FLAG_NOESCAPE',
45
            'FLAG_MUSTACHELOOKUP',
46
            'FLAG_ERROR_SKIPPARTIAL',
47
            'FLAG_MUSTACHELAMBDA',
48
            'FLAG_NOHBHELPERS',
49
            'FLAG_RENDER_DEBUG',
50
            'FLAG_BESTPERFORMANCE',
51
            'FLAG_JS',
52
            'FLAG_INSTANCE',
53
            'FLAG_MUSTACHE',
54
            'FLAG_HANDLEBARS',
55
            'FLAG_HANDLEBARSJS',
56
            'FLAG_HANDLEBARSJS_FULL',
57
        );
58 12
        $treeBuilder = new TreeBuilder();
59 12
        $rootNode = $treeBuilder->root('handlebars')
60 12
            ->fixXmlConfig('path')
61 12
            ->children()
62 12
                ->booleanNode('assetic')->end()
63 12
                ->scalarNode('cache')->defaultValue('%kernel.cache_dir%/handlebars')->end()
64 12
                ->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
65 12
                ->booleanNode('auto_reload')->defaultValue('%kernel.debug%')->end()
66 12
                ->arrayNode('translation')
67 12
                    ->addDefaultsIfNotSet()
68 12
                    ->children()
69 12
                        ->scalarNode('default_namespace')->defaultValue(null)->end()
70 12
                        ->scalarNode('interpolation_prefix')->defaultValue('%')->end()
71 12
                        ->scalarNode('interpolation_suffix')->defaultValue('%')->end()
72 12
                    ->end()
73 12
                ->end()
74 12
                ->arrayNode('flags')
75 12
                    ->prototype('enum')
76 12
                        ->values($flags)
77 12
                    ->end()
78 12
                ->end()
79 12
                ->arrayNode('excludeFlags')
80 12
                    ->prototype('enum')
81 12
                        ->values($flags)
82 12
                    ->end()
83 12
                ->end()
84 12
                ->arrayNode('paths')
85 12
                    ->normalizeKeys(false)
86 12
                    ->useAttributeAsKey('paths')
87 12
                    ->beforeNormalization()
88 12
                        ->always()
89 12
                        ->then(function ($paths) {
90 2
                            $normalized = array();
91 2
                            foreach ($paths as $path => $namespace) {
92 2
                                if (is_array($namespace)) {
93
                                    // xml
94
                                    $path = $namespace['value'];
95
                                    $namespace = $namespace['namespace'];
96
                                }
97
98
                                // path within the default namespace
99 2
                                if (ctype_digit((string) $path)) {
100 2
                                    $path = $namespace;
101 2
                                    $namespace = null;
102
                                }
103
104 2
                                $normalized[$path] = $namespace;
105
                            }
106
107 2
                            return $normalized;
108 12
                        })
109 12
                        ->end()
110 12
                    ->prototype('variable')->end()
111 12
                ->end()
112 12
            ->end();
113
114 12
        return $treeBuilder;
115
    }
116
}
117