Passed
Pull Request — develop (#8)
by ANTHONIUS
04:34
created

Configuration::configureFilterSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 31
nc 1
nop 1
dl 0
loc 35
ccs 31
cts 31
cp 1
crap 1
rs 9.424
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/behat-coverage-extension 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\Behat\Coverage;
15
16
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17
18
class Configuration
19
{
20 6
    public function configure(ArrayNodeDefinition $node)
21
    {
22 6
        $this->configureCoverageSection($node);
23 6
        $this->configureSessionSection($node);
24 6
        $this->configureReportSection($node);
25 6
        $this->configureFilterSection($node);
26
    }
27
28 6
    private function configureCoverageSection(ArrayNodeDefinition $node)
29
    {
30
        $node
31 6
            ->children()
32 6
                ->arrayNode('coverage')
33 6
                    ->addDefaultsIfNotSet()
34 6
                    ->children()
35 6
                        ->booleanNode('processUncoveredFilesFromWhitelist')->defaultFalse()->end()
36 6
                        ->booleanNode('checkForUnintentionallyCoveredCode')->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

36
                        ->/** @scrutinizer ignore-call */ booleanNode('checkForUnintentionallyCoveredCode')->defaultFalse()->end()
Loading history...
37 6
                        ->booleanNode('forceCoversAnnotation')->defaultFalse()->end()
38 6
                        ->booleanNode('checkForMissingCoversAnnotation')->defaultFalse()->end()
39 6
                        ->booleanNode('checkForUnexecutedCoveredCode')->defaultFalse()->end()
40 6
                        ->booleanNode('addUncoveredFilesFromWhitelist')->defaultTrue()->end()
41 6
                        ->booleanNode('disableIgnoredLines')->defaultFalse()->end()
42 6
                        ->booleanNode('ignoreDeprecatedCode')->defaultFalse()->end()
43 6
                        ->arrayNode('unintentionallyCoveredSubclassesWhitelist')
44 6
                            ->scalarPrototype()->end()
45 6
                        ->end()
46 6
                    ->end()
47 6
                ->end()
48 6
            ->end();
49
    }
50
51
    /**
52
     * Configure remote section.
53
     *
54
     * @return ArrayNodeDefinition
55
     */
56 6
    private function configureSessionSection(ArrayNodeDefinition $node)
57
    {
58
        $node
59 6
            ->addDefaultsIfNotSet()
60 6
            ->children()
61 6
                ->arrayNode('sessions')
62 6
                    ->useAttributeAsKey('name', false)
63 6
                    ->arrayPrototype()
64 6
                        ->children()
65 6
                            ->enumNode('driver')
66 6
                                ->values(['local', 'remote'])
67 6
                                ->defaultValue('local')
68 6
                            ->end()
69 6
                            ->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

69
                            ->/** @scrutinizer ignore-call */ scalarNode('remote_url')->end()
Loading history...
70 6
                        ->end()
71 6
                    ->end()
72 6
                ->end()
73 6
            ->end();
74
    }
75
76 6
    private function configureReportSection(ArrayNodeDefinition $builder)
77
    {
78
        $builder
79 6
            ->addDefaultsIfNotSet()
80 6
            ->children()
81 6
                ->arrayNode('report')
82 6
                    ->addDefaultsIfNotSet()
83 6
                    ->children()
84 6
                        ->append($this->addOptionsNode('clover'))
85 6
                        ->append($this->addOptionsNode('crap4j'))
86 6
                        ->append($this->addOptionsNode('html'))
87 6
                        ->append($this->addOptionsNode('php'))
88 6
                        ->append($this->addOptionsNode('text'))
89 6
                        ->append($this->addOptionsNode('xml'))
90 6
                    ->end()
91 6
                ->end()
92 6
            ->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

92
            ->/** @scrutinizer ignore-call */ end();
Loading history...
93
    }
94
95
    /**
96
     * @param string $name
97
     *
98
     * @return ArrayNodeDefinition
99
     */
100 6
    private function addOptionsNode($name)
101
    {
102 6
        $treeBuilder = new ArrayNodeDefinition($name);
103
        $normalizer  = function ($v) {
104
            return [
105 6
                'target' => $v,
106
            ];
107 6
        };
108
109
        return $treeBuilder
110 6
            ->beforeNormalization()
111 6
                ->ifString()->then($normalizer)
112 6
            ->end()
113 6
            ->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

113
            ->/** @scrutinizer ignore-call */ scalarPrototype()->end();
Loading history...
114
    }
115
116 6
    private function configureFilterSection(ArrayNodeDefinition $builder)
117
    {
118
        $stringNormalizer = function ($v) {
119 6
            return ['directory' => $v];
120 6
        };
121
122
        $builder
123 6
            ->children()
124 6
                ->arrayNode('filter')
125 6
                    ->arrayPrototype()
126 6
                        ->beforeNormalization()
127 6
                            ->ifString()->then($stringNormalizer)
128 6
                        ->end()
129 6
                        ->children()
130 6
                            ->scalarNode('directory')->defaultNull()->end()
131 6
                            ->scalarNode('file')->defaultNull()->end()
132 6
                            ->scalarNode('suffix')->defaultValue('.php')->end()
133 6
                            ->scalarNode('prefix')->defaultValue('')->end()
134 6
                            ->arrayNode('exclude')
135 6
                                ->arrayPrototype()
136 6
                                    ->beforeNormalization()
137 6
                                        ->ifString()->then($stringNormalizer)
138 6
                                    ->end()
139 6
                                    ->children()
140 6
                                        ->scalarNode('directory')->defaultNull()->end()
141 6
                                        ->scalarNode('file')->defaultNull()->end()
142 6
                                        ->scalarNode('suffix')->defaultNull()->end()
143 6
                                        ->scalarNode('prefix')->defaultNull()->end()
144 6
                                    ->end()
145 6
                                ->end()
146 6
                            ->end()
147 6
                        ->end()
148 6
                    ->end()
149 6
                ->end()
150 6
            ->end();
151
    }
152
}
153