Completed
Push — master ( ae46cd...5f7f67 )
by Steevan
02:24
created

Configuration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 96
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 10 1
B addTranslationConfig() 0 24 1
A addValidateSchemaConfig() 0 48 1
1
<?php
2
3
namespace steevanb\DevBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
class Configuration implements ConfigurationInterface
10
{
11
    /**
12
     * @return TreeBuilder
13
     */
14
    public function getConfigTreeBuilder()
15
    {
16
        $treeBuilder = new TreeBuilder();
17
        $rootNode = $treeBuilder->root('dev');
18
19
        $this->addTranslationConfig($rootNode->children());
20
        $this->addValidateSchemaConfig($rootNode->children());
21
22
        return $treeBuilder;
23
    }
24
25
    /**
26
     * @param NodeBuilder $node
27
     */
28
    protected function addTranslationConfig(NodeBuilder $node)
29
    {
30
        $node
31
            ->arrayNode('translation_not_found')
32
                ->addDefaultsIfNotSet()
33
                ->children()
34
                    ->scalarNode('enabled')
35
                        ->defaultTrue()
36
                        ->validate()
37
                        ->ifNotInArray(array(true, false))
38
                            ->thenInvalid('Invalid value %s, boolean required.')
39
                        ->end()
40
                    ->end()
41
                    ->scalarNode('allow_fallbacks')
42
                        ->defaultFalse()
43
                        ->validate()
44
                        ->ifNotInArray(array(true, false))
45
                            ->thenInvalid('Invalid value %s, boolean required.')
46
                        ->end()
47
                    ->end()
48
                ->end()
49
            ->end()
50
        ;
51
    }
52
53
    /**
54
     * @param NodeBuilder $node
55
     */
56
    protected function addValidateSchemaConfig(NodeBuilder $node)
57
    {
58
        $node
59
            ->arrayNode('validate_schema')
60
                ->addDefaultsIfNotSet()
61
                ->children()
62
                    ->scalarNode('enabled')
63
                        ->defaultTrue()
64
                        ->validate()
65
                        ->ifNotInArray(array(true, false))
66
                            ->thenInvalid('Invalid value %s, boolean required.')
67
                        ->end()
68
                    ->end()
69
                    ->arrayNode('disabled_urls')
70
                        ->defaultValue(array('/_wdt', '/_profiler/', '/_errors'))
71
                        ->prototype('scalar')->end()
72
                    ->end()
73
                    ->scalarNode('event')
74
                        ->defaultValue('kernel.request')
75
                        ->validate()
76
                        ->ifNotInArray(array('kernel.request', 'kernel.response'))
77
                            ->thenInvalid('Invalid value %s, should be kernel.request or kernel.response.')
78
                        ->end()
79
                    ->end()
80
                    ->arrayNode('excludes')
81
                        ->prototype('scalar')->end()
82
                    ->end()
83
                    ->arrayNode('paths')
84
                        ->prototype('scalar')->end()
85
                    ->end()
86
                    ->arrayNode('bundles')
87
                        ->addDefaultsIfNotSet()
88
                        ->children()
89
                            ->scalarNode('enabled')
90
                                ->defaultTrue()
91
                                ->validate()
92
                                ->ifNotInArray(array(true, false))
93
                                    ->thenInvalid('Invalid value %s, boolean required.')
94
                                ->end()
95
                            ->end()
96
                            ->arrayNode('bundles')
97
                                ->prototype('scalar')->end()
98
                            ->end()
99
                        ->end()
100
                    ->end()
101
                ->end()
102
            ->end();
103
    }
104
}
105