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')); |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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(); |
|
|
|
|
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
|
|
|
|
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.