Completed
Push — feature/null-coalescing-assign... ( 42d45d...cc67f8 )
by Kyle
43:35 queued 28:18
created

TreeBuilder::getRootNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of PDepend.
4
 *
5
 * PHP Version 5
6
 *
7
 * Copyright (c) 2008-2017 Manuel Pichler <[email protected]>.
8
 * All rights reserved.
9
 *
10
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions
12
 * are met:
13
 *
14
 *   * Redistributions of source code must retain the above copyright
15
 *     notice, this list of conditions and the following disclaimer.
16
 *
17
 *   * Redistributions in binary form must reproduce the above copyright
18
 *     notice, this list of conditions and the following disclaimer in
19
 *     the documentation and/or other materials provided with the
20
 *     distribution.
21
 *
22
 *   * Neither the name of Manuel Pichler nor the names of his
23
 *     contributors may be used to endorse or promote products derived
24
 *     from this software without specific prior written permission.
25
 *
26
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
 * POSSIBILITY OF SUCH DAMAGE.
38
 *
39
 * @copyright 2008-2017 Manuel Pichler. All rights reserved.
40
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41
 */
42
43
namespace PDepend\DependencyInjection;
44
45
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
46
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
47
use Symfony\Component\Config\Definition\Builder\TreeBuilder as BaseTreeBuilder;
48
49
/**
50
 * This is the class that embed the Symfony TreeBuilder and its root node.
51
 */
52
class TreeBuilder
53
{
54
    /**
55
     * @var NodeDefinition|ArrayNodeDefinition
56
     */
57
    protected $rootNode;
58
59
    /**
60
     * @var BaseTreeBuilder
61
     */
62
    protected $treeBuilder;
63
64
    /**
65
     * TreeBuilder constructor.
66
     *
67
     * @param string $name
68
     */
69 3
    public function __construct($name = 'pdepend')
70
    {
71 3
        if (method_exists('Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder', 'root')) {
72
            // Symfony < 5
73
            $this->treeBuilder = new BaseTreeBuilder();
0 ignored issues
show
Bug introduced by
The call to TreeBuilder::__construct() misses a required argument $name.

This check looks for function calls that miss required arguments.

Loading history...
74
            $this->rootNode = $this->treeBuilder->root($name);
0 ignored issues
show
Bug introduced by
The method root() does not seem to exist on object<Symfony\Component...on\Builder\TreeBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
76
            return;
77
        }
78
79
        // Symfony 5+
80 3
        $this->treeBuilder = new BaseTreeBuilder($name);
81 3
        $this->rootNode = $this->treeBuilder->getRootNode();
82
    }
83
84
    /**
85
     * Get the root node of the built tree.
86
     *
87
     * @return ArrayNodeDefinition|NodeDefinition
88
     */
89 3
    public function getRootNode()
90
    {
91 3
        return $this->rootNode;
92
    }
93
94
    /**
95
     * Get the base Symfony tree builder.
96
     *
97
     * @return BaseTreeBuilder
98
     */
99 3
    public function getTreeBuilder()
100
    {
101 3
        return $this->treeBuilder;
102
    }
103
}
104