Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0054

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 8
cts 9
cp 0.8889
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0054
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 6
        $treeBuilder = new TreeBuilder('cache_adapter');
33
34 6
        if (method_exists($treeBuilder, 'getRootNode')) {
35 6
            $rootNode = $treeBuilder->getRootNode();
36
        } else {
37
            $rootNode = $treeBuilder->root('cache_adapter');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
38
        }
39
40 6
        $rootNode->children()
41 6
            ->append($this->getClustersNode())
42 6
            ->end();
43
44 6
        return $treeBuilder;
45
    }
46
47
    /**
48
     * @return ArrayNodeDefinition
49
     */
50 6
    private function getClustersNode()
51
    {
52 6
        $treeBuilder = new TreeBuilder('providers');
53
54 6
        if (method_exists($treeBuilder, 'getRootNode')) {
55 6
            $node = $treeBuilder->getRootNode();
56
        } else {
57
            $node = $treeBuilder->root('providers');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
58
        }
59
60
        $node
61 6
            ->requiresAtLeastOneElement()
62 6
            ->useAttributeAsKey('name')
63 6
            ->prototype('array')
64 6
                ->children()
65 6
                    ->scalarNode('factory')->isRequired()->cannotBeEmpty()->end()
66 6
                    ->variableNode('options')->defaultValue([])->end()
67 6
                    ->arrayNode('aliases')
68 6
                        ->prototype('scalar')->end()
69 6
                    ->end()
70 6
                ->end()
71 6
            ->end();
72
73 6
        return $node;
74
    }
75
}
76