Passed
Pull Request — master (#15)
by ANTHONIUS
03:02
created

Configuration::configureReportSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 22
nc 1
nop 1
dl 0
loc 24
ccs 0
cts 24
cp 0
crap 2
rs 9.568
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/code-coverage project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\Bridge\CodeCoverage;
15
16
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18
use Symfony\Component\Config\Definition\ConfigurationInterface;
19
20
class Configuration implements ConfigurationInterface
21
{
22
    /**
23
     * @var callable
24
     */
25
    private $stringToArrayNormalizer;
26
27
    public function __construct()
28
    {
29
        $this->stringToArrayNormalizer  = function ($v) {
30
            return [
31
                'target' => $v,
32
            ];
33
        };
34
    }
35
36
    /**
37
     * @return TreeBuilder
38
     */
39
    public function getConfigTreeBuilder()
40
    {
41
        $treeBuilder = new TreeBuilder();
42
        $this->configure($treeBuilder->root('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

42
        $this->configure(/** @scrutinizer ignore-deprecated */ $treeBuilder->root('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...
43
44
        return $treeBuilder;
45
    }
46
47
    public function configure(ArrayNodeDefinition $node)
48
    {
49
        $this->configureCoverageSection($node);
50
        $this->configureSessionSection($node);
51
        $this->configureReportSection($node);
52
        $this->configureFilterSection($node);
53
54
        return $node;
55
    }
56
57
    private function configureCoverageSection(ArrayNodeDefinition $node)
58
    {
59
        $node
60
            ->children()
61
                ->booleanNode('xdebug_patch')->defaultTrue()->end()
62
                ->arrayNode('coverage')
0 ignored issues
show
Bug introduced by
The method arrayNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

62
                ->/** @scrutinizer ignore-call */ arrayNode('coverage')
Loading history...
63
                    ->addDefaultsIfNotSet()
64
                    ->children()
65
                        ->booleanNode('processUncoveredFilesFromWhitelist')->defaultFalse()->end()
66
                        ->booleanNode('checkForUnintentionallyCoveredCode')->defaultFalse()->end()
67
                        ->booleanNode('forceCoversAnnotation')->defaultFalse()->end()
68
                        ->booleanNode('checkForMissingCoversAnnotation')->defaultFalse()->end()
69
                        ->booleanNode('checkForUnexecutedCoveredCode')->defaultFalse()->end()
70
                        ->booleanNode('addUncoveredFilesFromWhitelist')->defaultTrue()->end()
71
                        ->booleanNode('disableIgnoredLines')->defaultFalse()->end()
72
                        ->booleanNode('ignoreDeprecatedCode')->defaultFalse()->end()
73
                        ->arrayNode('unintentionallyCoveredSubclassesWhitelist')
74
                            ->scalarPrototype()->end()
75
                        ->end()
76
                    ->end()
77
                ->end()
78
            ->end();
79
    }
80
81
    /**
82
     * Configure remote section.
83
     *
84
     * @return ArrayNodeDefinition
85
     */
86
    private function configureSessionSection(ArrayNodeDefinition $node)
87
    {
88
        $node
89
            ->addDefaultsIfNotSet()
90
            ->children()
91
                ->arrayNode('sessions')
92
                    ->useAttributeAsKey('name', false)
93
                    ->arrayPrototype()
94
                        ->children()
95
                            ->enumNode('driver')
96
                                ->values(['local', 'remote'])
97
                                ->defaultValue('local')
98
                            ->end()
99
                            ->scalarNode('remote_url')->end()
0 ignored issues
show
Bug introduced by
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

99
                            ->/** @scrutinizer ignore-call */ scalarNode('remote_url')->end()
Loading history...
100
                        ->end()
101
                    ->end()
102
                ->end()
103
            ->end();
104
    }
105
106
    private function configureReportSection(ArrayNodeDefinition $builder)
107
    {
108
        $builder
109
            ->addDefaultsIfNotSet()
110
            ->children()
111
                ->arrayNode('reports')
112
                    ->addDefaultsIfNotSet()
113
                    ->children()
114
                        ->append($this->addOptionsNode('clover'))
115
                        ->append($this->addOptionsNode('crap4j'))
116
                        ->append($this->addOptionsNode('html'))
117
                        ->append($this->addOptionsNode('php'))
118
                        ->arrayNode('text')
119
                            ->beforeNormalization()
120
                                ->ifString()->then($this->stringToArrayNormalizer)
121
                            ->end()
122
                            ->children()
123
                                ->scalarNode('target')->defaultValue('console')->end()
124
                            ->end()
125
                        ->end()
126
                        ->append($this->addOptionsNode('xml'))
127
                    ->end()
128
                ->end()
129
            ->end();
130
    }
131
132
    /**
133
     * @param string $name
134
     *
135
     * @return ArrayNodeDefinition
136
     */
137
    private function addOptionsNode($name)
138
    {
139
        $treeBuilder = new ArrayNodeDefinition($name);
140
141
        return $treeBuilder
142
            ->beforeNormalization()
143
                ->ifString()->then($this->stringToArrayNormalizer)
144
            ->end()
145
            ->scalarPrototype()->end();
0 ignored issues
show
Bug introduced by
The method scalarPrototype() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

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

145
            ->/** @scrutinizer ignore-call */ scalarPrototype()->end();
Loading history...
146
    }
147
148
    private function configureFilterSection(ArrayNodeDefinition $builder)
149
    {
150
        $stringNormalizer = function ($v) {
151
            return ['directory' => $v];
152
        };
153
154
        $builder
155
            ->children()
156
                ->arrayNode('filter')
157
                    ->arrayPrototype()
158
                        ->beforeNormalization()
159
                            ->ifString()->then($stringNormalizer)
160
                        ->end()
161
                        ->children()
162
                            ->scalarNode('directory')->defaultNull()->end()
163
                            ->scalarNode('file')->defaultNull()->end()
164
                            ->scalarNode('suffix')->defaultValue('.php')->end()
165
                            ->scalarNode('prefix')->defaultValue('')->end()
166
                            ->arrayNode('exclude')
167
                                ->arrayPrototype()
168
                                    ->beforeNormalization()
169
                                        ->ifString()->then($stringNormalizer)
170
                                    ->end()
171
                                    ->children()
172
                                        ->scalarNode('directory')->defaultNull()->end()
173
                                        ->scalarNode('file')->defaultNull()->end()
174
                                        ->scalarNode('suffix')->defaultNull()->end()
175
                                        ->scalarNode('prefix')->defaultNull()->end()
176
                                    ->end()
177
                                ->end()
178
                            ->end()
179
                        ->end()
180
                    ->end()
181
                ->end()
182
            ->end();
183
    }
184
}
185