Passed
Pull Request — master (#15)
by ANTHONIUS
07:35
created

Configuration::configureReportSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 22
nc 1
nop 1
dl 0
loc 24
ccs 22
cts 22
cp 1
crap 1
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 3
    public function __construct()
28
    {
29
        $this->stringToArrayNormalizer  = function ($v) {
30
            return [
31 1
                'target' => $v,
32
            ];
33
        };
34 3
    }
35
36
    /**
37
     * @return TreeBuilder
38
     */
39 3
    public function getConfigTreeBuilder()
40
    {
41 3
        $treeBuilder = new TreeBuilder();
42 3
        $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 3
        return $treeBuilder;
45
    }
46
47 3
    public function configure(ArrayNodeDefinition $node)
48
    {
49 3
        $this->configureCoverageSection($node);
50 3
        $this->configureSessionSection($node);
51 3
        $this->configureReportSection($node);
52 3
        $this->configureFilterSection($node);
53
54 3
        return $node;
55
    }
56
57 3
    private function configureCoverageSection(ArrayNodeDefinition $node)
58
    {
59
        $node
60 3
            ->children()
61 3
                ->booleanNode('xdebug_patch')->defaultTrue()->end()
62 3
                ->booleanNode('debug')->defaultFalse()->end()
0 ignored issues
show
Bug introduced by
The method booleanNode() 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 */ booleanNode('debug')->defaultFalse()->end()
Loading history...
63 3
                ->arrayNode('coverage')
64 3
                    ->addDefaultsIfNotSet()
65 3
                    ->children()
66 3
                        ->booleanNode('processUncoveredFilesFromWhitelist')->defaultFalse()->end()
67 3
                        ->booleanNode('checkForUnintentionallyCoveredCode')->defaultFalse()->end()
68 3
                        ->booleanNode('forceCoversAnnotation')->defaultFalse()->end()
69 3
                        ->booleanNode('checkForMissingCoversAnnotation')->defaultFalse()->end()
70 3
                        ->booleanNode('checkForUnexecutedCoveredCode')->defaultFalse()->end()
71 3
                        ->booleanNode('addUncoveredFilesFromWhitelist')->defaultTrue()->end()
72 3
                        ->booleanNode('disableIgnoredLines')->defaultFalse()->end()
73 3
                        ->booleanNode('ignoreDeprecatedCode')->defaultFalse()->end()
74 3
                        ->arrayNode('unintentionallyCoveredSubclassesWhitelist')
75 3
                            ->scalarPrototype()->end()
76 3
                        ->end()
77 3
                    ->end()
78 3
                ->end()
79 3
            ->end();
80 3
    }
81
82
    /**
83
     * Configure remote section.
84
     *
85
     * @return ArrayNodeDefinition
86
     */
87 3
    private function configureSessionSection(ArrayNodeDefinition $node)
88
    {
89
        $node
90 3
            ->addDefaultsIfNotSet()
91 3
            ->children()
92 3
                ->arrayNode('sessions')
93 3
                    ->useAttributeAsKey('name', false)
94 3
                    ->arrayPrototype()
95 3
                        ->children()
96 3
                            ->enumNode('driver')
97 3
                                ->values(['local', 'remote'])
98 3
                                ->defaultValue('local')
99 3
                            ->end()
100 3
                            ->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

100
                            ->/** @scrutinizer ignore-call */ scalarNode('remote_url')->end()
Loading history...
101 3
                        ->end()
102 3
                    ->end()
103 3
                ->end()
104 3
            ->end();
105 3
    }
106
107 3
    private function configureReportSection(ArrayNodeDefinition $builder)
108
    {
109
        $builder
110 3
            ->addDefaultsIfNotSet()
111 3
            ->children()
112 3
                ->arrayNode('reports')
113 3
                    ->addDefaultsIfNotSet()
114 3
                    ->children()
115 3
                        ->append($this->addOptionsNode('clover'))
116 3
                        ->append($this->addOptionsNode('crap4j'))
117 3
                        ->append($this->addOptionsNode('html'))
118 3
                        ->append($this->addOptionsNode('php'))
119 3
                        ->arrayNode('text')
120 3
                            ->beforeNormalization()
121 3
                                ->ifString()->then($this->stringToArrayNormalizer)
122 3
                            ->end()
123 3
                            ->children()
124 3
                                ->scalarNode('target')->defaultValue('console')->end()
125 3
                            ->end()
126 3
                        ->end()
127 3
                        ->append($this->addOptionsNode('xml'))
128 3
                    ->end()
129 3
                ->end()
130 3
            ->end();
131 3
    }
132
133
    /**
134
     * @param string $name
135
     *
136
     * @return ArrayNodeDefinition
137
     */
138 3
    private function addOptionsNode($name)
139
    {
140 3
        $treeBuilder = new ArrayNodeDefinition($name);
141
142
        return $treeBuilder
143 3
            ->beforeNormalization()
144 3
                ->ifString()->then($this->stringToArrayNormalizer)
145 3
            ->end()
146 3
            ->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

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