Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 6
Paths 1

Size

Total Lines 48

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 6.0087

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 30
cts 32
cp 0.9375
rs 8.5123
c 0
b 0
f 0
cc 6
nc 1
nop 0
crap 6.0087
1
<?php
2
3
namespace Happyr\BlazeBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * This is the class that validates and merges configuration from your app/config files.
10
 *
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13
class Configuration implements ConfigurationInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 2
    public function getConfigTreeBuilder()
19
    {
20 2
        $treeBuilder = new TreeBuilder('happyr_blaze');
21 2
        $rootNode = $treeBuilder->getRootNode();
22
23 2
        $rootNode->children()
24 2
            ->arrayNode('objects')
25 2
                ->requiresAtLeastOneElement()
26 2
                ->useAttributeAsKey('name')
27 2
                ->prototype('variable')
28 2
                ->treatNullLike([])
29
30
                //make sure that there is some config after each object
31 2
                ->validate()
32 2
                    ->ifTrue(
33 2
                        function ($objects) {
34 1
                            foreach ($objects as $o) {
35 1
                                if (!is_array($o)) {
36
                                    return true;
37
                                }
38
                            }
39
40 1
                            return false;
41 2
                        }
42
                    )
43 2
                    ->thenInvalid('The happyr_blaze.objects config %s must be an array.')
44 2
                ->end()
45
46
                //make sure route and parameters is set
47 2
                ->validate()
48 2
                ->ifTrue(
49 2
                    function ($objects) {
50 1
                        foreach ($objects as $o) {
51 1
                            if (!isset($o['route']) || !isset($o['parameters'])) {
52
                                return true;
53
                            }
54
                        }
55
56 1
                        return false;
57 2
                    }
58
                )
59 2
                ->thenInvalid('%s must contain "route" and "parameters".')
60 2
                ->end()
61 2
            ->end()
62 2
            ->end();
63
64 2
        return $treeBuilder;
65
    }
66
}
67