Configuration   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
cbo 4
dl 0
loc 89
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 21 1
B getProfilesNode() 0 33 1
B getTasksNode() 0 27 1
1
<?php
2
3
/**
4
 * This file is part of Bldr.io
5
 *
6
 * (c) Aaron Scherer <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE
10
 */
11
12
namespace Bldr\Block\Core;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
/**
18
 * @author Aaron Scherer <[email protected]>
19
 */
20
class Configuration implements ConfigurationInterface
21
{
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function getConfigTreeBuilder()
26
    {
27
        $treeBuilder = new TreeBuilder();
28
        $rootNode    = $treeBuilder->root('bldr');
29
30
        $rootNode
31
            ->addDefaultsIfNotSet()
32
            ->children()
33
                ->scalarNode('name')
34
                    ->defaultValue('')
35
                ->end()
36
                ->scalarNode('description')
37
                    ->defaultValue('')
38
                ->end()
39
                ->append($this->getProfilesNode())
40
                ->append($this->getTasksNode())
41
            ->end()
42
        ;
43
44
        return $treeBuilder;
45
    }
46
47
    private function getProfilesNode()
48
    {
49
        $treeBuilder = new TreeBuilder();
50
        $node        = $treeBuilder->root('profiles');
51
52
        $node
53
            ->requiresAtLeastOneElement()
54
            ->useAttributeAsKey('name')
55
            ->prototype('array')
56
                ->addDefaultsIfNotSet()
57
                ->children()
58
                    ->scalarNode('description')
59
                        ->defaultValue('')
60
                    ->end()
61
                    ->arrayNode('uses')
62
                        ->children()
63
                            ->arrayNode('before')
64
                                ->prototype('scalar')->end()
65
                            ->end()
66
                            ->arrayNode('after')
67
                                ->prototype('scalar')->end()
68
                            ->end()
69
                        ->end()
70
                    ->end()
71
                    ->arrayNode('jobs')
72
                        ->prototype('scalar')->end()
73
                    ->end()
74
                ->end()
75
            ->end()
76
        ;
77
78
        return $node;
79
    }
80
81
    private function getTasksNode()
82
    {
83
        $treeBuilder = new TreeBuilder();
84
        $node        = $treeBuilder->root('jobs');
85
86
        $node
87
            ->useAttributeAsKey('name')
88
            ->prototype('array')
89
                ->addDefaultsIfNotSet()
90
                ->children()
91
                    ->scalarNode('description')->defaultValue('')->end()
92
                    ->arrayNode('tasks')
93
                        ->requiresAtLeastOneElement()
94
                        ->prototype('array')
95
                            ->ignoreExtraKeys()
96
                            ->children()
97
                                ->scalarNode('type')->isRequired()->end()
98
                                ->booleanNode('continueOnError')->defaultFalse()->end()
99
                            ->end()
100
                        ->end()
101
                    ->end()
102
                ->end()
103
            ->end()
104
        ;
105
106
        return $node;
107
    }
108
}
109