9
9
*/
10
10
namespace SebastianBergmann \CodeCoverage \Report ;
11
11
12
- use function assert ;
13
- use function basename ;
14
12
use function count ;
15
13
use function dirname ;
16
14
use function file_put_contents ;
19
17
use function max ;
20
18
use function range ;
21
19
use function str_contains ;
22
- use function str_replace ;
23
20
use function time ;
24
21
use DOMDocument ;
25
- use DOMElement ;
26
22
use SebastianBergmann \CodeCoverage \CodeCoverage ;
27
23
use SebastianBergmann \CodeCoverage \Node \File ;
28
24
use SebastianBergmann \CodeCoverage \Util \Filesystem ;
29
- use SebastianBergmann \CodeCoverage \Version ;
30
25
use SebastianBergmann \CodeCoverage \WriteOperationFailedException ;
31
26
32
27
final class Clover
@@ -42,7 +37,6 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string
42
37
$ xmlDocument ->formatOutput = true ;
43
38
44
39
$ xmlCoverage = $ xmlDocument ->createElement ('coverage ' );
45
- $ xmlCoverage ->setAttribute ('clover ' , Version::id ());
46
40
$ xmlCoverage ->setAttribute ('generated ' , $ time );
47
41
$ xmlDocument ->appendChild ($ xmlCoverage );
48
42
@@ -55,7 +49,6 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string
55
49
56
50
$ xmlCoverage ->appendChild ($ xmlProject );
57
51
58
- /** @var array<non-empty-string, DOMElement> $packages */
59
52
$ packages = [];
60
53
$ report = $ coverage ->getReport ();
61
54
@@ -64,9 +57,10 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string
64
57
continue ;
65
58
}
66
59
60
+ /* @var File $item */
61
+
67
62
$ xmlFile = $ xmlDocument ->createElement ('file ' );
68
- $ xmlFile ->setAttribute ('name ' , basename ($ item ->pathAsString ()));
69
- $ xmlFile ->setAttribute ('path ' , $ item ->pathAsString ());
63
+ $ xmlFile ->setAttribute ('name ' , $ item ->pathAsString ());
70
64
71
65
$ classes = $ item ->classesAndTraits ();
72
66
$ coverageData = $ item ->lineCoverageData ();
@@ -110,28 +104,30 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string
110
104
$ lines [$ method ['startLine ' ]] = [
111
105
'ccn ' => $ method ['ccn ' ],
112
106
'count ' => $ methodCount ,
107
+ 'crap ' => $ method ['crap ' ],
113
108
'type ' => 'method ' ,
114
- 'signature ' => $ method ['signature ' ],
115
109
'visibility ' => $ method ['visibility ' ],
110
+ 'name ' => $ methodName ,
116
111
];
117
112
}
118
113
119
114
$ xmlClass = $ xmlDocument ->createElement ('class ' );
120
- $ xmlClass ->setAttribute ('name ' , str_replace ($ class ['namespace ' ] . '\\' , '' , $ className ));
115
+ $ xmlClass ->setAttribute ('name ' , $ className );
116
+ $ xmlClass ->setAttribute ('namespace ' , $ namespace );
121
117
122
118
$ xmlFile ->appendChild ($ xmlClass );
123
119
124
120
$ xmlMetrics = $ xmlDocument ->createElement ('metrics ' );
125
121
$ xmlMetrics ->setAttribute ('complexity ' , (string ) $ class ['ccn ' ]);
126
- $ xmlMetrics ->setAttribute ('elements ' , (string ) ( $ classMethods + $ classStatements + $ class [ ' executableBranches ' ]) );
127
- $ xmlMetrics ->setAttribute ('coveredelements ' , (string ) ( $ coveredMethods + $ coveredClassStatements + $ class [ ' executedBranches ' ]) );
122
+ $ xmlMetrics ->setAttribute ('methods ' , (string ) $ classMethods );
123
+ $ xmlMetrics ->setAttribute ('coveredmethods ' , (string ) $ coveredMethods );
128
124
$ xmlMetrics ->setAttribute ('conditionals ' , (string ) $ class ['executableBranches ' ]);
129
125
$ xmlMetrics ->setAttribute ('coveredconditionals ' , (string ) $ class ['executedBranches ' ]);
130
126
$ xmlMetrics ->setAttribute ('statements ' , (string ) $ classStatements );
131
127
$ xmlMetrics ->setAttribute ('coveredstatements ' , (string ) $ coveredClassStatements );
132
- $ xmlMetrics ->setAttribute ('methods ' , (string ) $ classMethods );
133
- $ xmlMetrics ->setAttribute ('coveredmethods ' , (string ) $ coveredMethods );
134
- $ xmlClass ->insertBefore ($ xmlMetrics, $ xmlClass -> firstChild );
128
+ $ xmlMetrics ->setAttribute ('elements ' , (string ) ( $ classMethods + $ classStatements + $ class [ ' executableBranches ' ]) );
129
+ $ xmlMetrics ->setAttribute ('coveredelements ' , (string ) ( $ coveredMethods + $ coveredClassStatements + $ class [ ' executedBranches ' ]) );
130
+ $ xmlClass ->appendChild ($ xmlMetrics );
135
131
}
136
132
137
133
foreach ($ coverageData as $ line => $ data ) {
@@ -140,8 +136,7 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string
140
136
}
141
137
142
138
$ lines [$ line ] = [
143
- 'count ' => count ($ data ),
144
- 'type ' => 'stmt ' ,
139
+ 'count ' => count ($ data ), 'type ' => 'stmt ' ,
145
140
];
146
141
}
147
142
@@ -152,20 +147,23 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string
152
147
$ xmlLine ->setAttribute ('num ' , (string ) $ line );
153
148
$ xmlLine ->setAttribute ('type ' , $ data ['type ' ]);
154
149
155
- if (isset ($ data ['ccn ' ])) {
156
- $ xmlLine ->setAttribute ('complexity ' , ( string ) $ data ['ccn ' ]);
150
+ if (isset ($ data ['name ' ])) {
151
+ $ xmlLine ->setAttribute ('name ' , $ data ['name ' ]);
157
152
}
158
153
159
- $ xmlLine ->setAttribute ('count ' , (string ) $ data ['count ' ]);
154
+ if (isset ($ data ['visibility ' ])) {
155
+ $ xmlLine ->setAttribute ('visibility ' , $ data ['visibility ' ]);
156
+ }
160
157
161
- if (isset ($ data ['signature ' ])) {
162
- $ xmlLine ->setAttribute ('signature ' , $ data ['signature ' ]);
158
+ if (isset ($ data ['ccn ' ])) {
159
+ $ xmlLine ->setAttribute ('complexity ' , ( string ) $ data ['ccn ' ]);
163
160
}
164
161
165
- if (isset ($ data ['visibility ' ])) {
166
- $ xmlLine ->setAttribute ('visibility ' , $ data ['visibility ' ]);
162
+ if (isset ($ data ['crap ' ])) {
163
+ $ xmlLine ->setAttribute ('crap ' , ( string ) $ data ['crap ' ]);
167
164
}
168
165
166
+ $ xmlLine ->setAttribute ('count ' , (string ) $ data ['count ' ]);
169
167
$ xmlFile ->appendChild ($ xmlLine );
170
168
}
171
169
@@ -175,51 +173,30 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string
175
173
$ xmlMetrics ->setAttribute ('loc ' , (string ) $ linesOfCode ->linesOfCode ());
176
174
$ xmlMetrics ->setAttribute ('ncloc ' , (string ) $ linesOfCode ->nonCommentLinesOfCode ());
177
175
$ xmlMetrics ->setAttribute ('classes ' , (string ) $ item ->numberOfClassesAndTraits ());
178
- $ xmlMetrics ->setAttribute ('complexity ' , (string ) $ item ->cyclomaticComplexity ());
179
- $ xmlMetrics ->setAttribute ('elements ' , (string ) ($ item ->numberOfMethods () + $ item ->numberOfExecutableLines () + $ item ->numberOfExecutableBranches ()));
180
- $ xmlMetrics ->setAttribute ('coveredelements ' , (string ) ($ item ->numberOfTestedMethods () + $ item ->numberOfExecutedLines () + $ item ->numberOfExecutedBranches ()));
176
+ $ xmlMetrics ->setAttribute ('methods ' , (string ) $ item ->numberOfMethods ());
177
+ $ xmlMetrics ->setAttribute ('coveredmethods ' , (string ) $ item ->numberOfTestedMethods ());
181
178
$ xmlMetrics ->setAttribute ('conditionals ' , (string ) $ item ->numberOfExecutableBranches ());
182
179
$ xmlMetrics ->setAttribute ('coveredconditionals ' , (string ) $ item ->numberOfExecutedBranches ());
183
180
$ xmlMetrics ->setAttribute ('statements ' , (string ) $ item ->numberOfExecutableLines ());
184
181
$ xmlMetrics ->setAttribute ('coveredstatements ' , (string ) $ item ->numberOfExecutedLines ());
185
- $ xmlMetrics ->setAttribute ('methods ' , (string ) $ item ->numberOfMethods ());
186
- $ xmlMetrics ->setAttribute ('coveredmethods ' , (string ) $ item ->numberOfTestedMethods ());
187
- $ xmlFile ->insertBefore ($ xmlMetrics , $ xmlFile ->firstChild );
188
-
189
- if (!isset ($ packages [$ namespace ])) {
190
- $ packages [$ namespace ] = $ xmlDocument ->createElement ('package ' );
191
- $ packages [$ namespace ]->setAttribute ('name ' , $ namespace );
192
-
193
- $ xmlPackageMetrics = $ xmlDocument ->createElement ('metrics ' );
194
- $ xmlPackageMetrics ->setAttribute ('complexity ' , '0 ' );
195
- $ xmlPackageMetrics ->setAttribute ('elements ' , '0 ' );
196
- $ xmlPackageMetrics ->setAttribute ('coveredelements ' , '0 ' );
197
- $ xmlPackageMetrics ->setAttribute ('conditionals ' , '0 ' );
198
- $ xmlPackageMetrics ->setAttribute ('coveredconditionals ' , '0 ' );
199
- $ xmlPackageMetrics ->setAttribute ('statements ' , '0 ' );
200
- $ xmlPackageMetrics ->setAttribute ('coveredstatements ' , '0 ' );
201
- $ xmlPackageMetrics ->setAttribute ('methods ' , '0 ' );
202
- $ xmlPackageMetrics ->setAttribute ('coveredmethods ' , '0 ' );
203
- $ packages [$ namespace ]->appendChild ($ xmlPackageMetrics );
204
-
205
- $ xmlProject ->appendChild ($ packages [$ namespace ]);
206
- }
207
-
208
- $ xmlPackageMetrics = $ packages [$ namespace ]->firstChild ;
209
-
210
- assert ($ xmlPackageMetrics instanceof DOMElement);
211
-
212
- $ xmlPackageMetrics ->setAttribute ('complexity ' , (string ) ((int ) $ xmlPackageMetrics ->getAttribute ('complexity ' ) + $ item ->cyclomaticComplexity ()));
213
- $ xmlPackageMetrics ->setAttribute ('elements ' , (string ) ((int ) $ xmlPackageMetrics ->getAttribute ('elements ' ) + $ item ->numberOfMethods () + $ item ->numberOfExecutableLines () + $ item ->numberOfExecutableBranches ()));
214
- $ xmlPackageMetrics ->setAttribute ('coveredelements ' , (string ) ((int ) $ xmlPackageMetrics ->getAttribute ('coveredelements ' ) + $ item ->numberOfTestedMethods () + $ item ->numberOfExecutedLines () + $ item ->numberOfExecutedBranches ()));
215
- $ xmlPackageMetrics ->setAttribute ('conditionals ' , (string ) ((int ) $ xmlPackageMetrics ->getAttribute ('conditionals ' ) + $ item ->numberOfExecutableBranches ()));
216
- $ xmlPackageMetrics ->setAttribute ('coveredconditionals ' , (string ) ((int ) $ xmlPackageMetrics ->getAttribute ('coveredconditionals ' ) + $ item ->numberOfExecutedBranches ()));
217
- $ xmlPackageMetrics ->setAttribute ('statements ' , (string ) ((int ) $ xmlPackageMetrics ->getAttribute ('statements ' ) + $ item ->numberOfExecutableLines ()));
218
- $ xmlPackageMetrics ->setAttribute ('coveredstatements ' , (string ) ((int ) $ xmlPackageMetrics ->getAttribute ('coveredstatements ' ) + $ item ->numberOfExecutedLines ()));
219
- $ xmlPackageMetrics ->setAttribute ('methods ' , (string ) ((int ) $ xmlPackageMetrics ->getAttribute ('methods ' ) + $ item ->numberOfMethods ()));
220
- $ xmlPackageMetrics ->setAttribute ('coveredmethods ' , (string ) ((int ) $ xmlPackageMetrics ->getAttribute ('coveredmethods ' ) + $ item ->numberOfTestedMethods ()));
182
+ $ xmlMetrics ->setAttribute ('elements ' , (string ) ($ item ->numberOfMethods () + $ item ->numberOfExecutableLines () + $ item ->numberOfExecutableBranches ()));
183
+ $ xmlMetrics ->setAttribute ('coveredelements ' , (string ) ($ item ->numberOfTestedMethods () + $ item ->numberOfExecutedLines () + $ item ->numberOfExecutedBranches ()));
184
+ $ xmlFile ->appendChild ($ xmlMetrics );
185
+
186
+ if ($ namespace === 'global ' ) {
187
+ $ xmlProject ->appendChild ($ xmlFile );
188
+ } else {
189
+ if (!isset ($ packages [$ namespace ])) {
190
+ $ packages [$ namespace ] = $ xmlDocument ->createElement (
191
+ 'package ' ,
192
+ );
193
+
194
+ $ packages [$ namespace ]->setAttribute ('name ' , $ namespace );
195
+ $ xmlProject ->appendChild ($ packages [$ namespace ]);
196
+ }
221
197
222
- $ packages [$ namespace ]->appendChild ($ xmlFile );
198
+ $ packages [$ namespace ]->appendChild ($ xmlFile );
199
+ }
223
200
}
224
201
225
202
$ linesOfCode = $ report ->linesOfCode ();
@@ -229,16 +206,15 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string
229
206
$ xmlMetrics ->setAttribute ('loc ' , (string ) $ linesOfCode ->linesOfCode ());
230
207
$ xmlMetrics ->setAttribute ('ncloc ' , (string ) $ linesOfCode ->nonCommentLinesOfCode ());
231
208
$ xmlMetrics ->setAttribute ('classes ' , (string ) $ report ->numberOfClassesAndTraits ());
232
- $ xmlMetrics ->setAttribute ('complexity ' , (string ) $ report ->cyclomaticComplexity ());
233
- $ xmlMetrics ->setAttribute ('elements ' , (string ) ($ report ->numberOfMethods () + $ report ->numberOfExecutableLines () + $ report ->numberOfExecutableBranches ()));
234
- $ xmlMetrics ->setAttribute ('coveredelements ' , (string ) ($ report ->numberOfTestedMethods () + $ report ->numberOfExecutedLines () + $ report ->numberOfExecutedBranches ()));
209
+ $ xmlMetrics ->setAttribute ('methods ' , (string ) $ report ->numberOfMethods ());
210
+ $ xmlMetrics ->setAttribute ('coveredmethods ' , (string ) $ report ->numberOfTestedMethods ());
235
211
$ xmlMetrics ->setAttribute ('conditionals ' , (string ) $ report ->numberOfExecutableBranches ());
236
212
$ xmlMetrics ->setAttribute ('coveredconditionals ' , (string ) $ report ->numberOfExecutedBranches ());
237
213
$ xmlMetrics ->setAttribute ('statements ' , (string ) $ report ->numberOfExecutableLines ());
238
214
$ xmlMetrics ->setAttribute ('coveredstatements ' , (string ) $ report ->numberOfExecutedLines ());
239
- $ xmlMetrics ->setAttribute ('methods ' , (string ) $ report ->numberOfMethods ());
240
- $ xmlMetrics ->setAttribute ('coveredmethods ' , (string ) $ report ->numberOfTestedMethods ());
241
- $ xmlProject ->insertBefore ($ xmlMetrics, $ xmlProject -> firstChild );
215
+ $ xmlMetrics ->setAttribute ('elements ' , (string ) ( $ report ->numberOfMethods () + $ report -> numberOfExecutableLines () + $ report -> numberOfExecutableBranches () ));
216
+ $ xmlMetrics ->setAttribute ('coveredelements ' , (string ) ( $ report ->numberOfTestedMethods () + $ report -> numberOfExecutedLines () + $ report -> numberOfExecutedBranches () ));
217
+ $ xmlProject ->appendChild ($ xmlMetrics );
242
218
243
219
$ buffer = $ xmlDocument ->saveXML ();
244
220
0 commit comments