@@ -70,12 +70,18 @@ final class Text
70
70
*/
71
71
private $ showOnlySummary ;
72
72
73
- public function __construct (int $ lowUpperBound = 50 , int $ highLowerBound = 90 , bool $ showUncoveredFiles = false , bool $ showOnlySummary = false )
73
+ /**
74
+ * @var bool
75
+ */
76
+ private $ determineBranchCoverage ;
77
+
78
+ public function __construct (int $ lowUpperBound = 50 , int $ highLowerBound = 90 , bool $ showUncoveredFiles = false , bool $ showOnlySummary = false , bool $ determineBranchCoverage = false )
74
79
{
75
- $ this ->lowUpperBound = $ lowUpperBound ;
76
- $ this ->highLowerBound = $ highLowerBound ;
77
- $ this ->showUncoveredFiles = $ showUncoveredFiles ;
78
- $ this ->showOnlySummary = $ showOnlySummary ;
80
+ $ this ->lowUpperBound = $ lowUpperBound ;
81
+ $ this ->highLowerBound = $ highLowerBound ;
82
+ $ this ->showUncoveredFiles = $ showUncoveredFiles ;
83
+ $ this ->showOnlySummary = $ showOnlySummary ;
84
+ $ this ->determineBranchCoverage = $ determineBranchCoverage ;
79
85
}
80
86
81
87
public function process (CodeCoverage $ coverage , bool $ showColors = false ): string
@@ -110,15 +116,17 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
110
116
$ report ->getNumExecutableLines ()
111
117
);
112
118
113
- $ colors ['branches ' ] = $ this ->getCoverageColor (
114
- $ report ->getNumTestedBranches (),
115
- $ report ->getNumBranches ()
116
- );
119
+ if ($ this ->determineBranchCoverage ) {
120
+ $ colors ['branches ' ] = $ this ->getCoverageColor (
121
+ $ report ->getNumTestedBranches (),
122
+ $ report ->getNumBranches ()
123
+ );
117
124
118
- $ colors ['paths ' ] = $ this ->getCoverageColor (
119
- $ report ->getNumTestedPaths (),
120
- $ report ->getNumPaths ()
121
- );
125
+ $ colors ['paths ' ] = $ this ->getCoverageColor (
126
+ $ report ->getNumTestedPaths (),
127
+ $ report ->getNumPaths ()
128
+ );
129
+ }
122
130
123
131
$ colors ['reset ' ] = self ::COLOR_RESET ;
124
132
$ colors ['header ' ] = self ::COLOR_HEADER ;
@@ -158,27 +166,32 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
158
166
$ report ->getNumExecutableLines ()
159
167
);
160
168
161
- $ branches = \sprintf (
162
- ' Branches: %6s (%d/%d) ' ,
163
- Util::percent (
169
+ $ paths = '' ;
170
+ $ branches = '' ;
171
+
172
+ if ($ this ->determineBranchCoverage ) {
173
+ $ branches = \sprintf (
174
+ ' Branches: %6s (%d/%d) ' ,
175
+ Util::percent (
176
+ $ report ->getNumTestedBranches (),
177
+ $ report ->getNumBranches (),
178
+ true
179
+ ),
164
180
$ report ->getNumTestedBranches (),
165
- $ report ->getNumBranches (),
166
- true
167
- ),
168
- $ report ->getNumTestedBranches (),
169
- $ report ->getNumBranches ()
170
- );
181
+ $ report ->getNumBranches ()
182
+ );
171
183
172
- $ paths = \sprintf (
173
- ' Paths: %6s (%d/%d) ' ,
174
- Util::percent (
184
+ $ paths = \sprintf (
185
+ ' Paths: %6s (%d/%d) ' ,
186
+ Util::percent (
187
+ $ report ->getNumTestedPaths (),
188
+ $ report ->getNumPaths (),
189
+ true
190
+ ),
175
191
$ report ->getNumTestedPaths (),
176
- $ report ->getNumPaths (),
177
- true
178
- ),
179
- $ report ->getNumTestedPaths (),
180
- $ report ->getNumPaths ()
181
- );
192
+ $ report ->getNumPaths ()
193
+ );
194
+ }
182
195
183
196
$ padding = \max (\array_map ('strlen ' , [$ classes , $ methods , $ lines ]));
184
197
@@ -200,8 +213,11 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
200
213
$ output .= $ this ->format ($ colors ['classes ' ], $ padding , $ classes );
201
214
$ output .= $ this ->format ($ colors ['methods ' ], $ padding , $ methods );
202
215
$ output .= $ this ->format ($ colors ['lines ' ], $ padding , $ lines );
203
- $ output .= $ this ->format ($ colors ['branches ' ], $ padding , $ branches );
204
- $ output .= $ this ->format ($ colors ['paths ' ], $ padding , $ paths );
216
+
217
+ if ($ this ->determineBranchCoverage ) {
218
+ $ output .= $ this ->format ($ colors ['branches ' ], $ padding , $ branches );
219
+ $ output .= $ this ->format ($ colors ['paths ' ], $ padding , $ paths );
220
+ }
205
221
206
222
if ($ this ->showOnlySummary ) {
207
223
return $ output . \PHP_EOL ;
@@ -239,10 +255,13 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
239
255
$ classMethods ++;
240
256
$ classStatements += $ method ['executableLines ' ];
241
257
$ coveredClassStatements += $ method ['executedLines ' ];
242
- $ classPaths += $ method ['executablePaths ' ];
243
- $ coveredClassPaths += $ method ['executedPaths ' ];
244
- $ classBranches += $ method ['executableBranches ' ];
245
- $ coveredClassBranches += $ method ['executedBranches ' ];
258
+
259
+ if ($ this ->determineBranchCoverage ) {
260
+ $ classPaths += $ method ['executablePaths ' ];
261
+ $ coveredClassPaths += $ method ['executedPaths ' ];
262
+ $ classBranches += $ method ['executableBranches ' ];
263
+ $ coveredClassBranches += $ method ['executedBranches ' ];
264
+ }
246
265
247
266
if ($ method ['coverage ' ] === 100 ) {
248
267
$ coveredMethods ++;
@@ -259,16 +278,19 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
259
278
\strlen ((string ) $ classStatements ),
260
279
\strlen ((string ) $ coveredClassStatements )
261
280
);
262
- $ maxBranches = \max (
263
- $ maxBranches ,
264
- \strlen ((string ) $ classBranches ),
265
- \strlen ((string ) $ coveredClassBranches )
266
- );
267
- $ maxPaths = \max (
268
- $ maxPaths ,
269
- \strlen ((string ) $ classPaths ),
270
- \strlen ((string ) $ coveredClassPaths )
271
- );
281
+
282
+ if ($ this ->determineBranchCoverage ) {
283
+ $ maxBranches = \max (
284
+ $ maxBranches ,
285
+ \strlen ((string ) $ classBranches ),
286
+ \strlen ((string ) $ coveredClassBranches )
287
+ );
288
+ $ maxPaths = \max (
289
+ $ maxPaths ,
290
+ \strlen ((string ) $ classPaths ),
291
+ \strlen ((string ) $ coveredClassPaths )
292
+ );
293
+ }
272
294
273
295
$ namespace = '' ;
274
296
@@ -306,16 +328,23 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
306
328
if ($ showColors ) {
307
329
$ methodColor = $ this ->getCoverageColor ($ classInfo ['methodsCovered ' ], $ classInfo ['methodCount ' ]);
308
330
$ linesColor = $ this ->getCoverageColor ($ classInfo ['statementsCovered ' ], $ classInfo ['statementCount ' ]);
309
- $ branchesColor = $ this ->getCoverageColor ($ classInfo ['branchesCovered ' ], $ classInfo ['branchCount ' ]);
310
- $ pathsColor = $ this ->getCoverageColor ($ classInfo ['pathsCovered ' ], $ classInfo ['pathCount ' ]);
331
+
332
+ if ($ this ->determineBranchCoverage ) {
333
+ $ branchesColor = $ this ->getCoverageColor ($ classInfo ['branchesCovered ' ], $ classInfo ['branchCount ' ]);
334
+ $ pathsColor = $ this ->getCoverageColor ($ classInfo ['pathsCovered ' ], $ classInfo ['pathCount ' ]);
335
+ }
311
336
$ resetColor = $ colors ['reset ' ];
312
337
}
313
338
314
339
$ output .= \PHP_EOL . $ fullQualifiedPath . \PHP_EOL
315
340
. ' ' . $ methodColor . 'Methods: ' . $ this ->printCoverageCounts ($ classInfo ['methodsCovered ' ], $ classInfo ['methodCount ' ], $ maxMethods ) . $ resetColor . ' '
316
- . ' ' . $ linesColor . 'Lines: ' . $ this ->printCoverageCounts ($ classInfo ['statementsCovered ' ], $ classInfo ['statementCount ' ], $ maxLines ) . $ resetColor . ' '
317
- . ' ' . $ branchesColor . 'Branches: ' . $ this ->printCoverageCounts ($ classInfo ['branchesCovered ' ], $ classInfo ['branchCount ' ], $ maxBranches ) . $ resetColor . ' '
318
- . ' ' . $ pathsColor . 'Paths: ' . $ this ->printCoverageCounts ($ classInfo ['pathsCovered ' ], $ classInfo ['pathCount ' ], $ maxPaths ) . $ resetColor ;
341
+ . ' ' . $ linesColor . 'Lines: ' . $ this ->printCoverageCounts ($ classInfo ['statementsCovered ' ], $ classInfo ['statementCount ' ], $ maxLines ) . $ resetColor ;
342
+
343
+ if ($ this ->determineBranchCoverage ) {
344
+ $ output .= ''
345
+ . ' ' . $ branchesColor . 'Branches: ' . $ this ->printCoverageCounts ($ classInfo ['branchesCovered ' ], $ classInfo ['branchCount ' ], $ maxBranches ) . $ resetColor . ' '
346
+ . ' ' . $ pathsColor . 'Paths: ' . $ this ->printCoverageCounts ($ classInfo ['pathsCovered ' ], $ classInfo ['pathCount ' ], $ maxPaths ) . $ resetColor ;
347
+ }
319
348
}
320
349
}
321
350
0 commit comments