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

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 3
Metric Value
wmc 4
c 6
b 1
f 3
lcom 0
cbo 2
dl 0
loc 105
ccs 48
cts 48
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 102 4
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