Test Failed
Push — master ( 4e8938...efe3fd )
by Peter
08:14 queued 11s
created

getConfigTreeBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 8
c 2
b 1
f 0
dl 0
loc 16
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace YamlStandards\Model\Config;
6
7
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
use Symfony\Component\Config\Definition\ConfigurationInterface;
10
use Symfony\Component\HttpKernel\Kernel;
11
12
class YamlStandardConfigDefinition implements ConfigurationInterface
13
{
14
    public const CONFIG_PATHS_TO_CHECK = 'pathsToCheck';
15
    public const CONFIG_EXCLUDED_PATHS = 'excludedPaths';
16
    public const CONFIG_CHECKERS = 'checkers';
17
    public const CONFIG_PATH_TO_CHECKER = 'pathToChecker';
18
    public const CONFIG_PARAMETERS_FOR_CHECKER = 'parameters';
19
    public const CONFIG_PARAMETERS_DEPTH = 'depth';
20
    public const CONFIG_PARAMETERS_INDENTS = 'indents';
21
    public const CONFIG_PARAMETERS_LEVEL = 'level';
22
23
    /**
24
     * @inheritDoc
25
     */
26
    public function getConfigTreeBuilder(): TreeBuilder
27
    {
28
        // fix for Symfony 4.2 and newer versions
29
        if (Kernel::VERSION_ID >= 40200) {
30
            $treeBuilder = new TreeBuilder('yaml_standards_config');
31
            /** @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $rootNode */
32
            $rootNode = $treeBuilder->getRootNode();
33
        } else {
34
            $treeBuilder = new TreeBuilder();
35
            /** @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $rootNode */
36
            $rootNode = $treeBuilder->root('yaml_standards_config');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

36
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('yaml_standards_config');

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

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

Loading history...
37
        }
38
39
        $this->buildItemsNode($rootNode->arrayPrototype());
40
41
        return $treeBuilder;
42
    }
43
44
    /**
45
     * @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node
46
     * @return \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition
47
     */
48
    private function buildItemsNode(ArrayNodeDefinition $node): ArrayNodeDefinition
49
    {
50
        return $node
51
            ->children()
52
                ->arrayNode(self::CONFIG_PATHS_TO_CHECK)->isRequired()->cannotBeEmpty()
53
                    ->prototype('scalar')->end()
54
                ->end()
0 ignored issues
show
Bug introduced by
The method end() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Config...ion\Builder\TreeBuilder. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
                ->/** @scrutinizer ignore-call */ end()
Loading history...
55
                ->arrayNode(self::CONFIG_EXCLUDED_PATHS)
56
                    ->prototype('scalar')->end()
57
                ->end()
58
                ->arrayNode(self::CONFIG_CHECKERS)
59
                    ->isRequired()
60
                    ->arrayPrototype()
61
                        ->children()
62
                            ->scalarNode(self::CONFIG_PATH_TO_CHECKER)->defaultNull()->end()
63
                            ->arrayNode(self::CONFIG_PARAMETERS_FOR_CHECKER)
64
                                ->addDefaultsIfNotSet()
65
                                    ->children()
66
                                        ->scalarNode(self::CONFIG_PARAMETERS_DEPTH)->defaultNull()->end()
67
                                        ->scalarNode(self::CONFIG_PARAMETERS_INDENTS)->defaultNull()->end()
68
                                        ->scalarNode(self::CONFIG_PARAMETERS_LEVEL)->defaultNull()->end()
69
                                    ->end()
70
                                ->end()
71
                            ->end()
72
                        ->end()
73
                    ->end()
74
                ->end()
75
            ->end();
76
    }
77
}
78