Completed
Push — master ( b209b1...84fcc2 )
by Peter
05:42
created

getConfigTreeBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0625

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 8
c 2
b 1
f 0
dl 0
loc 16
ccs 6
cts 8
cp 0.75
rs 10
cc 2
nc 2
nop 0
crap 2.0625
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
    public const CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE = 'serviceAliasingType';
23
24
    public const CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE_VALUE_SHORT = 'short';
25
    public const CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE_VALUE_LONG = 'long';
26
27
    /**
28
     * @inheritDoc
29
     */
30 9
    public function getConfigTreeBuilder(): TreeBuilder
31
    {
32
        // fix for Symfony 4.2 and newer versions
33 9
        if (Kernel::VERSION_ID >= 40200) {
34 9
            $treeBuilder = new TreeBuilder('yaml_standards_config');
35
            /** @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $rootNode */
36 9
            $rootNode = $treeBuilder->getRootNode();
37
        } else {
38
            $treeBuilder = new TreeBuilder();
39
            /** @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $rootNode */
40
            $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

40
            $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...
41
        }
42
43 9
        $this->buildItemsNode($rootNode->arrayPrototype());
44
45 9
        return $treeBuilder;
46
    }
47
48
    /**
49
     * @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node
50
     * @return \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition
51
     */
52 9
    private function buildItemsNode(ArrayNodeDefinition $node): ArrayNodeDefinition
53
    {
54
        return $node
55 9
            ->children()
56 9
                ->arrayNode(self::CONFIG_PATHS_TO_CHECK)->isRequired()->cannotBeEmpty()
57 9
                    ->prototype('scalar')->end()
58 9
                ->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

58
                ->/** @scrutinizer ignore-call */ end()
Loading history...
59 9
                ->arrayNode(self::CONFIG_EXCLUDED_PATHS)
60 9
                    ->prototype('scalar')->end()
61 9
                ->end()
62 9
                ->arrayNode(self::CONFIG_CHECKERS)
63 9
                    ->isRequired()
64 9
                    ->arrayPrototype()
65 9
                        ->children()
66 9
                            ->scalarNode(self::CONFIG_PATH_TO_CHECKER)->defaultNull()->end()
67 9
                            ->arrayNode(self::CONFIG_PARAMETERS_FOR_CHECKER)
68 9
                                ->addDefaultsIfNotSet()
69 9
                                    ->children()
70 9
                                        ->scalarNode(self::CONFIG_PARAMETERS_DEPTH)->defaultNull()->end()
71 9
                                        ->scalarNode(self::CONFIG_PARAMETERS_INDENTS)->defaultNull()->end()
72 9
                                        ->scalarNode(self::CONFIG_PARAMETERS_LEVEL)->defaultNull()->end()
73 9
                                        ->enumNode(self::CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE)->defaultNull()->values([
74 9
                                            self::CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE_VALUE_SHORT,
75 9
                                            self::CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE_VALUE_LONG,
76 9
                                        ])->end()
77 9
                                    ->end()
78 9
                                ->end()
79 9
                            ->end()
80 9
                        ->end()
81 9
                    ->end()
82 9
                ->end()
83 9
            ->end();
84
    }
85
}
86