Completed
Push — master ( d7fcc6...d5c5d6 )
by Tobias
10:49 queued 06:56
created

Configuration::getClustersNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2.0008

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 16
cts 17
cp 0.9412
rs 9.504
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0008
1
<?php
2
3
/*
4
 * This file is part of php-cache organization.
5
 *
6
 * (c) 2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[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 Cache\AdapterBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
18
/**
19
 * Class Configuration.
20
 *
21
 * @author Aaron Scherer <[email protected]>
22
 */
23
class Configuration implements ConfigurationInterface
24
{
25
    /**
26
     * Generates the configuration tree builder.
27
     *
28
     * @return TreeBuilder The tree builder
29
     */
30 6
    public function getConfigTreeBuilder()
31
    {
32
33 6
        $treeBuilder = new TreeBuilder('cache_adapter');
34
35 6
        if (method_exists($treeBuilder, 'getRootNode')) {
36 6
            $rootNode = $treeBuilder->getRootNode();
37
        } else {
38
            $rootNode = $treeBuilder->root('cache_adapter');
39
        }
40
41 6
        $rootNode->children()
42 6
            ->append($this->getClustersNode())
43 6
            ->end();
44
45 6
        return $treeBuilder;
46
    }
47
48
    /**
49
     * @return ArrayNodeDefinition
50
     */
51 6
    private function getClustersNode()
52
    {
53
54 6
        $treeBuilder = new TreeBuilder('providers');
55
56 6
        if (method_exists($treeBuilder, 'getRootNode')) {
57 6
            $node = $treeBuilder->getRootNode();
58
        } else {
59
            $node = $treeBuilder->root('providers');
60
        }
61
62
        $node
63 6
            ->requiresAtLeastOneElement()
64 6
            ->useAttributeAsKey('name')
65 6
            ->prototype('array')
66 6
                ->children()
67 6
                    ->scalarNode('factory')->isRequired()->cannotBeEmpty()->end()
68 6
                    ->variableNode('options')->defaultValue([])->end()
69 6
                    ->arrayNode('aliases')
70 6
                        ->prototype('scalar')->end()
71 6
                    ->end()
72 6
                ->end()
73 6
            ->end();
74
75 6
        return $node;
76
    }
77
}
78