Completed
Push — master ( 14b7c4...eb0b96 )
by Alexander
12:10 queued 12s
created

Configuration::getRootNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2015, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\Symfony\GoAopBundle\DependencyInjection;
12
13
14
use Go\Aop\Features;
15
use Go\Symfony\GoAopBundle\Kernel\AspectSymfonyKernel;
16
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18
use Symfony\Component\Config\Definition\ConfigurationInterface;
19
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
20
use Symfony\Component\HttpKernel\Kernel;
21
22
class Configuration implements ConfigurationInterface
23
{
24
    const CONFIGURATION_ROOT_NODE = 'go_aop';
25
26
    /**
27
     * Generates the configuration tree builder.
28
     *
29
     * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
30
     */
31
    public function getConfigTreeBuilder()
32
    {
33
        $treeBuilder = new TreeBuilder(self::CONFIGURATION_ROOT_NODE);
0 ignored issues
show
Unused Code introduced by
The call to TreeBuilder::__construct() has too many arguments starting with self::CONFIGURATION_ROOT_NODE.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
34
        $rootNode = $this->getRootNode($treeBuilder);
35
        $features = (new \ReflectionClass('Go\Aop\Features'))->getConstants();
36
37
        $rootNode
38
            ->children()
39
                ->booleanNode('cache_warmer')->defaultTrue()->end()
40
                ->booleanNode('doctrine_support')->defaultFalse()->end()
41
                ->arrayNode('options')
42
                    ->addDefaultsIfNotSet()
43
                    ->fixXmlConfig('feature', 'features')
44
                    ->fixXmlConfig('include_path', 'include_paths')
45
                    ->fixXmlConfig('exclude_path', 'exclude_paths')
46
                    ->children()
47
                        ->scalarNode('features')
48
                            ->beforeNormalization()
49
                                ->ifArray()
50
                                ->then(function ($v) use ($features) {
51
                                    $featureMask = 0;
52
                                    foreach ($v as $featureName) {
53
                                        $featureName = strtoupper($featureName);
54
                                        if (!isset($features[$featureName])) {
55
                                            throw new InvalidConfigurationException("Uknown feature: {$featureName}");
56
                                        }
57
                                        $featureMask |= $features[$featureName];
58
                                    }
59
60
                                    return $featureMask;
61
                                })
62
                            ->end()
63
                            ->defaultValue(0)
64
                        ->end()
65
                        ->scalarNode('app_dir')->defaultValue('%kernel.root_dir%/../src')->end()
66
                        ->scalarNode('cache_dir')->defaultValue('%kernel.cache_dir%/aspect')->end()
67
                        ->scalarNode('cache_file_mode')->end()
68
                        ->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
69
                        ->scalarNode('container_class')->end()
70
                        ->arrayNode('include_paths')
71
                            ->prototype('scalar')->end()
72
                        ->end()
73
                        ->arrayNode('exclude_paths')
74
                            ->prototype('scalar')->end()
75
                        ->end()
76
                    ->end()
77
                ->end()
78
            ->end()
79
        ;
80
81
        return $treeBuilder;
82
    }
83
84
    /**
85
     * @param TreeBuilder $treeBuilder
86
     *
87
     * @return ArrayNodeDefinition
88
     */
89
    private function getRootNode(TreeBuilder $treeBuilder)
90
    {
91
        if (Kernel::VERSION_ID >= 40200) {
92
            return $treeBuilder->getRootNode();
0 ignored issues
show
Bug introduced by
The method getRootNode() 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...
93
        }
94
95
        return $treeBuilder->root(self::CONFIGURATION_ROOT_NODE);
96
    }
97
}
98