Passed
Push — master ( 146be5...1e12ef )
by ANTHONIUS
06:12
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 7
    public function __construct()
28
    {
29
        $this->stringToArrayNormalizer  = function ($v) {
30
            return [
31 7
                'target' => $v,
32
            ];
33
        };
34
    }
35
36
    /**
37
     * @return TreeBuilder
38
     */
39 21
    public function getConfigTreeBuilder()
40
    {
41 21
        $treeBuilder = new TreeBuilder();
42 21
        $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 21
        return $treeBuilder;
45
    }
46
47 21
    public function configure(ArrayNodeDefinition $node)
48
    {
49 21
        $this->configureCoverageSection($node);
50 21
        $this->configureSessionSection($node);
51 21
        $this->configureReportSection($node);
52 21
        $this->configureFilterSection($node);
53
54 21
        return $node;
55
    }
56
57 21
    private function configureCoverageSection(ArrayNodeDefinition $node)
58
    {
59
        $node
60 21
            ->children()
61 21
                ->arrayNode('imports')
62 21
                    ->scalarPrototype()->end()
63 21
                ->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

63
                ->/** @scrutinizer ignore-call */ end()
Loading history...
64 21
                ->booleanNode('xdebug_patch')->defaultTrue()->end()
65 21
                ->booleanNode('debug')->defaultFalse()->end()
66 21
                ->arrayNode('coverage')
67 21
                    ->addDefaultsIfNotSet()
68 21
                    ->children()
69 21
                        ->booleanNode('processUncoveredFilesFromWhitelist')->defaultFalse()->end()
70 21
                        ->booleanNode('checkForUnintentionallyCoveredCode')->defaultFalse()->end()
71 21
                        ->booleanNode('forceCoversAnnotation')->defaultFalse()->end()
72 21
                        ->booleanNode('checkForMissingCoversAnnotation')->defaultFalse()->end()
73 21
                        ->booleanNode('checkForUnexecutedCoveredCode')->defaultFalse()->end()
74 21
                        ->booleanNode('addUncoveredFilesFromWhitelist')->defaultTrue()->end()
75 21
                        ->booleanNode('disableIgnoredLines')->defaultFalse()->end()
76 21
                        ->booleanNode('ignoreDeprecatedCode')->defaultFalse()->end()
77 21
                        ->arrayNode('unintentionallyCoveredSubclassesWhitelist')
78 21
                            ->scalarPrototype()->end()
79 21
                        ->end()
80 21
                    ->end()
81 21
                ->end()
82 21
            ->end();
83
    }
84
85
    /**
86
     * Configure remote section.
87
     *
88
     * @return ArrayNodeDefinition
89
     */
90 21
    private function configureSessionSection(ArrayNodeDefinition $node)
91
    {
92
        $node
93 21
            ->addDefaultsIfNotSet()
94 21
            ->children()
95 21
                ->arrayNode('sessions')
96 21
                    ->useAttributeAsKey('name', false)
97 21
                    ->arrayPrototype()
98 21
                        ->children()
99 21
                            ->enumNode('driver')
100 21
                                ->values(['local', 'remote'])
101 21
                                ->defaultValue('local')
102 21
                            ->end()
103 21
                            ->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

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

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