Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 109

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 54
CRAP Score 4.0007

Importance

Changes 0
Metric Value
dl 0
loc 109
ccs 54
cts 56
cp 0.9643
rs 8
c 0
b 0
f 0
cc 4
nc 1
nop 0
crap 4.0007

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 @jenschude <[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 7
    public function getConfigTreeBuilder()
15
    {
16
        $flags = array(
17 7
            '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 7
        $treeBuilder = new TreeBuilder();
59 7
        $rootNode = $treeBuilder->root('handlebars');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
60
        $rootNode
61 7
            ->fixXmlConfig('path')
62 7
            ->children()
63 7
                ->booleanNode('assetic')->end()
64 7
                ->scalarNode('cache')->defaultValue('%kernel.cache_dir%/handlebars')->end()
65 7
                ->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
66 7
                ->booleanNode('auto_reload')->defaultValue('%kernel.debug%')->end()
67 7
                ->arrayNode('cms')
68 7
                    ->addDefaultsIfNotSet()
69 7
                    ->children()
70 7
                        ->scalarNode('default_namespace')->defaultValue(null)->end()
71 7
                    ->end()
72 7
                ->end()
73 7
                ->arrayNode('translation')
74 7
                    ->addDefaultsIfNotSet()
75 7
                    ->children()
76 7
                        ->scalarNode('default_namespace')->defaultValue(null)->end()
77 7
                        ->scalarNode('interpolation_prefix')->defaultValue('%')->end()
78 7
                        ->scalarNode('interpolation_suffix')->defaultValue('%')->end()
79 7
                    ->end()
80 7
                ->end()
81 7
                ->arrayNode('flags')
82 7
                    ->prototype('enum')
83 7
                        ->values($flags)
84 7
                    ->end()
85 7
                ->end()
86 7
                ->arrayNode('excludeFlags')
87 7
                    ->prototype('enum')
88 7
                        ->values($flags)
89 7
                    ->end()
90 7
                ->end()
91 7
                ->arrayNode('paths')
92 7
                    ->normalizeKeys(false)
93 7
                    ->useAttributeAsKey('paths')
94 7
                    ->beforeNormalization()
95 7
                        ->always()
96 7
                        ->then(function($paths) {
97 1
                            $normalized = array();
98 1
                            foreach ($paths as $path => $namespace) {
99 1
                                if (is_array($namespace)) {
100
                                    // xml
101
                                    $path = $namespace['value'];
102
                                    $namespace = $namespace['namespace'];
103
                                }
104
105
                                // path within the default namespace
106 1
                                if (ctype_digit((string) $path)) {
107 1
                                    $path = $namespace;
108 1
                                    $namespace = null;
109
                                }
110
111 1
                                $normalized[$path] = $namespace;
112
                            }
113
114 1
                            return $normalized;
115 7
                        })
116 7
                        ->end()
117 7
                    ->prototype('variable')->end()
118 7
                ->end()
119 7
            ->end();
120
121 7
        return $treeBuilder;
122
    }
123
}
124