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

Configuration::configureReportSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 19
nc 1
nop 1
dl 0
loc 21
ccs 19
cts 19
cp 1
crap 1
rs 9.6333
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
     * @return TreeBuilder
24
     */
25 1
    public function getConfigTreeBuilder()
26
    {
27 1
        $treeBuilder = new TreeBuilder();
28 1
        $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

28
        $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...
29
30 1
        return $treeBuilder;
31
    }
32
33 1
    public function configure(ArrayNodeDefinition $node)
34
    {
35 1
        $this->configureCoverageSection($node);
36 1
        $this->configureSessionSection($node);
37 1
        $this->configureReportSection($node);
38 1
        $this->configureFilterSection($node);
39
40 1
        return $node;
41
    }
42
43 1
    private function configureCoverageSection(ArrayNodeDefinition $node)
44
    {
45
        $node
46 1
            ->children()
47 1
                ->booleanNode('xdebug_patch')->defaultTrue()->end()
48 1
                ->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

48
                ->/** @scrutinizer ignore-call */ arrayNode('coverage')
Loading history...
49 1
                    ->addDefaultsIfNotSet()
50 1
                    ->children()
51 1
                        ->booleanNode('processUncoveredFilesFromWhitelist')->defaultFalse()->end()
52 1
                        ->booleanNode('checkForUnintentionallyCoveredCode')->defaultFalse()->end()
53 1
                        ->booleanNode('forceCoversAnnotation')->defaultFalse()->end()
54 1
                        ->booleanNode('checkForMissingCoversAnnotation')->defaultFalse()->end()
55 1
                        ->booleanNode('checkForUnexecutedCoveredCode')->defaultFalse()->end()
56 1
                        ->booleanNode('addUncoveredFilesFromWhitelist')->defaultTrue()->end()
57 1
                        ->booleanNode('disableIgnoredLines')->defaultFalse()->end()
58 1
                        ->booleanNode('ignoreDeprecatedCode')->defaultFalse()->end()
59 1
                        ->arrayNode('unintentionallyCoveredSubclassesWhitelist')
60 1
                            ->scalarPrototype()->end()
61 1
                        ->end()
62 1
                    ->end()
63 1
                ->end()
64 1
            ->end();
65
    }
66
67
    /**
68
     * Configure remote section.
69
     *
70
     * @return ArrayNodeDefinition
71
     */
72 1
    private function configureSessionSection(ArrayNodeDefinition $node)
73
    {
74
        $node
75 1
            ->addDefaultsIfNotSet()
76 1
            ->children()
77 1
                ->arrayNode('sessions')
78 1
                    ->useAttributeAsKey('name', false)
79 1
                    ->arrayPrototype()
80 1
                        ->children()
81 1
                            ->enumNode('driver')
82 1
                                ->values(['local', 'remote'])
83 1
                                ->defaultValue('local')
84 1
                            ->end()
85 1
                            ->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

85
                            ->/** @scrutinizer ignore-call */ scalarNode('remote_url')->end()
Loading history...
86 1
                        ->end()
87 1
                    ->end()
88 1
                ->end()
89 1
            ->end();
90
    }
91
92 1
    private function configureReportSection(ArrayNodeDefinition $builder)
93
    {
94
        $builder
95 1
            ->addDefaultsIfNotSet()
96 1
            ->children()
97 1
                ->arrayNode('reports')
98 1
                    ->addDefaultsIfNotSet()
99 1
                    ->children()
100 1
                        ->append($this->addOptionsNode('clover'))
101 1
                        ->append($this->addOptionsNode('crap4j'))
102 1
                        ->append($this->addOptionsNode('html'))
103 1
                        ->append($this->addOptionsNode('php'))
104 1
                        ->arrayNode('text')
105 1
                            ->children()
106 1
                                ->scalarNode('target')->defaultValue('console')->end()
107 1
                            ->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

107
                            ->/** @scrutinizer ignore-call */ end()
Loading history...
108 1
                        ->end()
109 1
                        ->append($this->addOptionsNode('xml'))
110 1
                    ->end()
111 1
                ->end()
112 1
            ->end();
113
    }
114
115
    /**
116
     * @param string $name
117
     *
118
     * @return ArrayNodeDefinition
119
     */
120 1
    private function addOptionsNode($name)
121
    {
122 1
        $treeBuilder = new ArrayNodeDefinition($name);
123
        $normalizer  = function ($v) {
124
            return [
125
                'target' => $v,
126
            ];
127 1
        };
128
129
        return $treeBuilder
130 1
            ->beforeNormalization()
131 1
                ->ifString()->then($normalizer)
132 1
            ->end()
133 1
            ->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

133
            ->/** @scrutinizer ignore-call */ scalarPrototype()->end();
Loading history...
134
    }
135
136 1
    private function configureFilterSection(ArrayNodeDefinition $builder)
137
    {
138
        $stringNormalizer = function ($v) {
139
            return ['directory' => $v];
140 1
        };
141
142
        $builder
143 1
            ->children()
144 1
                ->arrayNode('filter')
145 1
                    ->arrayPrototype()
146 1
                        ->beforeNormalization()
147 1
                            ->ifString()->then($stringNormalizer)
148 1
                        ->end()
149 1
                        ->children()
150 1
                            ->scalarNode('directory')->defaultNull()->end()
151 1
                            ->scalarNode('file')->defaultNull()->end()
152 1
                            ->scalarNode('suffix')->defaultValue('.php')->end()
153 1
                            ->scalarNode('prefix')->defaultValue('')->end()
154 1
                            ->arrayNode('exclude')
155 1
                                ->arrayPrototype()
156 1
                                    ->beforeNormalization()
157 1
                                        ->ifString()->then($stringNormalizer)
158 1
                                    ->end()
159 1
                                    ->children()
160 1
                                        ->scalarNode('directory')->defaultNull()->end()
161 1
                                        ->scalarNode('file')->defaultNull()->end()
162 1
                                        ->scalarNode('suffix')->defaultNull()->end()
163 1
                                        ->scalarNode('prefix')->defaultNull()->end()
164 1
                                    ->end()
165 1
                                ->end()
166 1
                            ->end()
167 1
                        ->end()
168 1
                    ->end()
169 1
                ->end()
170 1
            ->end();
171
    }
172
}
173