Completed
Push — develop ( e7703b...db1330 )
by Jens
15:05
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 96.43%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 112
ccs 54
cts 56
cp 0.9643
rs 10
c 0
b 0
f 0

1 Method

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