Completed
Push — master ( 6b1baa...9e395d )
by ANTHONIUS
16s queued 11s
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/behat-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 15
    public function getConfigTreeBuilder()
40
    {
41 15
        $treeBuilder = new TreeBuilder();
42 15
        $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 15
        return $treeBuilder;
45
    }
46
47 15
    public function configure(ArrayNodeDefinition $node)
48
    {
49 15
        $this->configureCoverageSection($node);
50 15
        $this->configureSessionSection($node);
51 15
        $this->configureReportSection($node);
52 15
        $this->configureFilterSection($node);
53
54 15
        return $node;
55
    }
56
57 15
    private function configureCoverageSection(ArrayNodeDefinition $node)
58
    {
59
        $node
60 15
            ->children()
61 15
                ->booleanNode('xdebug_patch')->defaultTrue()->end()
62 15
                ->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 15
                    ->addDefaultsIfNotSet()
64 15
                    ->children()
65 15
                        ->booleanNode('processUncoveredFilesFromWhitelist')->defaultFalse()->end()
66 15
                        ->booleanNode('checkForUnintentionallyCoveredCode')->defaultFalse()->end()
67 15
                        ->booleanNode('forceCoversAnnotation')->defaultFalse()->end()
68 15
                        ->booleanNode('checkForMissingCoversAnnotation')->defaultFalse()->end()
69 15
                        ->booleanNode('checkForUnexecutedCoveredCode')->defaultFalse()->end()
70 15
                        ->booleanNode('addUncoveredFilesFromWhitelist')->defaultTrue()->end()
71 15
                        ->booleanNode('disableIgnoredLines')->defaultFalse()->end()
72 15
                        ->booleanNode('ignoreDeprecatedCode')->defaultFalse()->end()
73 15
                        ->arrayNode('unintentionallyCoveredSubclassesWhitelist')
74 15
                            ->scalarPrototype()->end()
75 15
                        ->end()
76 15
                    ->end()
77 15
                ->end()
78 15
            ->end();
79
    }
80
81
    /**
82
     * Configure remote section.
83
     *
84
     * @return ArrayNodeDefinition
85
     */
86 15
    private function configureSessionSection(ArrayNodeDefinition $node)
87
    {
88
        $node
89 15
            ->addDefaultsIfNotSet()
90 15
            ->children()
91 15
                ->arrayNode('sessions')
92 15
                    ->useAttributeAsKey('name', false)
93 15
                    ->arrayPrototype()
94 15
                        ->children()
95 15
                            ->enumNode('driver')
96 15
                                ->values(['local', 'remote'])
97 15
                                ->defaultValue('local')
98 15
                            ->end()
99 15
                            ->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 15
                        ->end()
101 15
                    ->end()
102 15
                ->end()
103 15
            ->end();
104
    }
105
106 15
    private function configureReportSection(ArrayNodeDefinition $builder)
107
    {
108
        $builder
109 15
            ->addDefaultsIfNotSet()
110 15
            ->children()
111 15
                ->arrayNode('reports')
112 15
                    ->addDefaultsIfNotSet()
113 15
                    ->children()
114 15
                        ->append($this->addOptionsNode('clover'))
115 15
                        ->append($this->addOptionsNode('crap4j'))
116 15
                        ->append($this->addOptionsNode('html'))
117 15
                        ->append($this->addOptionsNode('php'))
118 15
                        ->arrayNode('text')
119 15
                            ->beforeNormalization()
120 15
                                ->ifString()->then($this->stringToArrayNormalizer)
121 15
                            ->end()
122 15
                            ->children()
123 15
                                ->scalarNode('target')->defaultValue('console')->end()
124 15
                            ->end()
125 15
                        ->end()
126 15
                        ->append($this->addOptionsNode('xml'))
127 15
                    ->end()
128 15
                ->end()
129 15
            ->end();
130
    }
131
132
    /**
133
     * @param string $name
134
     *
135
     * @return ArrayNodeDefinition
136
     */
137 15
    private function addOptionsNode($name)
138
    {
139 15
        $treeBuilder = new ArrayNodeDefinition($name);
140
141
        return $treeBuilder
142 15
            ->beforeNormalization()
143 15
                ->ifString()->then($this->stringToArrayNormalizer)
144 15
            ->end()
145 15
            ->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 15
    private function configureFilterSection(ArrayNodeDefinition $builder)
149
    {
150
        $stringNormalizer = function ($v) {
151
            return ['directory' => $v];
152 15
        };
153
154
        $builder
155 15
            ->children()
156 15
                ->arrayNode('filter')
157 15
                    ->arrayPrototype()
158 15
                        ->beforeNormalization()
159 15
                            ->ifString()->then($stringNormalizer)
160 15
                        ->end()
161 15
                        ->children()
162 15
                            ->scalarNode('directory')->defaultNull()->end()
163 15
                            ->scalarNode('file')->defaultNull()->end()
164 15
                            ->scalarNode('suffix')->defaultValue('.php')->end()
165 15
                            ->scalarNode('prefix')->defaultValue('')->end()
166 15
                            ->arrayNode('exclude')
167 15
                                ->arrayPrototype()
168 15
                                    ->beforeNormalization()
169 15
                                        ->ifString()->then($stringNormalizer)
170 15
                                    ->end()
171 15
                                    ->children()
172 15
                                        ->scalarNode('directory')->defaultNull()->end()
173 15
                                        ->scalarNode('file')->defaultNull()->end()
174 15
                                        ->scalarNode('suffix')->defaultNull()->end()
175 15
                                        ->scalarNode('prefix')->defaultNull()->end()
176 15
                                    ->end()
177 15
                                ->end()
178 15
                            ->end()
179 15
                        ->end()
180 15
                    ->end()
181 15
                ->end()
182 15
            ->end();
183
    }
184
}
185