@@ -78,16 +78,20 @@ public function __construct(int $lowUpperBound = 50, int $highLowerBound = 90, b
7878
7979 public function process (CodeCoverage $ coverage , bool $ showColors = false ): string
8080 {
81+ $ hasBranchCoverage = !empty ($ coverage ->getData (true )->getFunctionCoverage ());
82+
8183 $ output = \PHP_EOL . \PHP_EOL ;
8284 $ report = $ coverage ->getReport ();
8385
8486 $ colors = [
85- 'header ' => '' ,
86- 'classes ' => '' ,
87- 'methods ' => '' ,
88- 'lines ' => '' ,
89- 'reset ' => '' ,
90- 'eol ' => '' ,
87+ 'header ' => '' ,
88+ 'classes ' => '' ,
89+ 'methods ' => '' ,
90+ 'lines ' => '' ,
91+ 'branches ' => '' ,
92+ 'paths ' => '' ,
93+ 'reset ' => '' ,
94+ 'eol ' => '' ,
9195 ];
9296
9397 if ($ showColors ) {
@@ -106,6 +110,16 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
106110 $ report ->getNumExecutableLines ()
107111 );
108112
113+ $ colors ['branches ' ] = $ this ->getCoverageColor (
114+ $ report ->getNumExecutedBranches (),
115+ $ report ->getNumExecutableBranches ()
116+ );
117+
118+ $ colors ['paths ' ] = $ this ->getCoverageColor (
119+ $ report ->getNumExecutedPaths (),
120+ $ report ->getNumExecutablePaths ()
121+ );
122+
109123 $ colors ['reset ' ] = self ::COLOR_RESET ;
110124 $ colors ['header ' ] = self ::COLOR_HEADER ;
111125 $ colors ['eol ' ] = self ::COLOR_EOL ;
@@ -131,6 +145,31 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
131145 $ report ->getNumMethods ()
132146 );
133147
148+ $ paths = '' ;
149+ $ branches = '' ;
150+
151+ if ($ hasBranchCoverage ) {
152+ $ paths = \sprintf (
153+ ' Paths: %6s (%d/%d) ' ,
154+ Percentage::fromFractionAndTotal (
155+ $ report ->getNumExecutedPaths (),
156+ $ report ->getNumExecutablePaths (),
157+ )->asString (),
158+ $ report ->getNumExecutedPaths (),
159+ $ report ->getNumExecutablePaths ()
160+ );
161+
162+ $ branches = \sprintf (
163+ ' Branches: %6s (%d/%d) ' ,
164+ Percentage::fromFractionAndTotal (
165+ $ report ->getNumExecutedBranches (),
166+ $ report ->getNumExecutableBranches (),
167+ )->asString (),
168+ $ report ->getNumExecutedBranches (),
169+ $ report ->getNumExecutableBranches ()
170+ );
171+ }
172+
134173 $ lines = \sprintf (
135174 ' Lines: %6s (%d/%d) ' ,
136175 Percentage::fromFractionAndTotal (
@@ -160,6 +199,11 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
160199
161200 $ output .= $ this ->format ($ colors ['classes ' ], $ padding , $ classes );
162201 $ output .= $ this ->format ($ colors ['methods ' ], $ padding , $ methods );
202+
203+ if ($ hasBranchCoverage ) {
204+ $ output .= $ this ->format ($ colors ['paths ' ], $ padding , $ paths );
205+ $ output .= $ this ->format ($ colors ['branches ' ], $ padding , $ branches );
206+ }
163207 $ output .= $ this ->format ($ colors ['lines ' ], $ padding , $ lines );
164208
165209 if ($ this ->showOnlySummary ) {
@@ -176,19 +220,27 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
176220 $ classes = $ item ->getClassesAndTraits ();
177221
178222 foreach ($ classes as $ className => $ class ) {
179- $ classStatements = 0 ;
180- $ coveredClassStatements = 0 ;
181- $ coveredMethods = 0 ;
182- $ classMethods = 0 ;
223+ $ classExecutableLines = 0 ;
224+ $ classExecutedLines = 0 ;
225+ $ classExecutableBranches = 0 ;
226+ $ classExecutedBranches = 0 ;
227+ $ classExecutablePaths = 0 ;
228+ $ classExecutedPaths = 0 ;
229+ $ coveredMethods = 0 ;
230+ $ classMethods = 0 ;
183231
184232 foreach ($ class ['methods ' ] as $ method ) {
185233 if ($ method ['executableLines ' ] == 0 ) {
186234 continue ;
187235 }
188236
189237 $ classMethods ++;
190- $ classStatements += $ method ['executableLines ' ];
191- $ coveredClassStatements += $ method ['executedLines ' ];
238+ $ classExecutableLines += $ method ['executableLines ' ];
239+ $ classExecutedLines += $ method ['executedLines ' ];
240+ $ classExecutableBranches += $ method ['executableBranches ' ];
241+ $ classExecutedBranches += $ method ['executedBranches ' ];
242+ $ classExecutablePaths += $ method ['executablePaths ' ];
243+ $ classExecutedPaths += $ method ['executedPaths ' ];
192244
193245 if ($ method ['coverage ' ] == 100 ) {
194246 $ coveredMethods ++;
@@ -206,29 +258,42 @@ public function process(CodeCoverage $coverage, bool $showColors = false): strin
206258 'className ' => $ className ,
207259 'methodsCovered ' => $ coveredMethods ,
208260 'methodCount ' => $ classMethods ,
209- 'statementsCovered ' => $ coveredClassStatements ,
210- 'statementCount ' => $ classStatements ,
261+ 'statementsCovered ' => $ classExecutedLines ,
262+ 'statementCount ' => $ classExecutableLines ,
263+ 'branchesCovered ' => $ classExecutedBranches ,
264+ 'branchesCount ' => $ classExecutableBranches ,
265+ 'pathsCovered ' => $ classExecutedPaths ,
266+ 'pathsCount ' => $ classExecutablePaths ,
211267 ];
212268 }
213269 }
214270
215271 \ksort ($ classCoverage );
216272
217- $ methodColor = '' ;
218- $ linesColor = '' ;
219- $ resetColor = '' ;
273+ $ methodColor = '' ;
274+ $ pathsColor = '' ;
275+ $ branchesColor = '' ;
276+ $ linesColor = '' ;
277+ $ resetColor = '' ;
220278
221279 foreach ($ classCoverage as $ fullQualifiedPath => $ classInfo ) {
222280 if ($ this ->showUncoveredFiles || $ classInfo ['statementsCovered ' ] != 0 ) {
223281 if ($ showColors ) {
224- $ methodColor = $ this ->getCoverageColor ($ classInfo ['methodsCovered ' ], $ classInfo ['methodCount ' ]);
225- $ linesColor = $ this ->getCoverageColor ($ classInfo ['statementsCovered ' ], $ classInfo ['statementCount ' ]);
226- $ resetColor = $ colors ['reset ' ];
282+ $ methodColor = $ this ->getCoverageColor ($ classInfo ['methodsCovered ' ], $ classInfo ['methodCount ' ]);
283+ $ pathsColor = $ this ->getCoverageColor ($ classInfo ['pathsCovered ' ], $ classInfo ['pathsCount ' ]);
284+ $ branchesColor = $ this ->getCoverageColor ($ classInfo ['branchesCovered ' ], $ classInfo ['branchesCount ' ]);
285+ $ linesColor = $ this ->getCoverageColor ($ classInfo ['statementsCovered ' ], $ classInfo ['statementCount ' ]);
286+ $ resetColor = $ colors ['reset ' ];
227287 }
228288
229289 $ output .= \PHP_EOL . $ fullQualifiedPath . \PHP_EOL
230- . ' ' . $ methodColor . 'Methods: ' . $ this ->printCoverageCounts ($ classInfo ['methodsCovered ' ], $ classInfo ['methodCount ' ], 2 ) . $ resetColor . ' '
231- . ' ' . $ linesColor . 'Lines: ' . $ this ->printCoverageCounts ($ classInfo ['statementsCovered ' ], $ classInfo ['statementCount ' ], 3 ) . $ resetColor ;
290+ . ' ' . $ methodColor . 'Methods: ' . $ this ->printCoverageCounts ($ classInfo ['methodsCovered ' ], $ classInfo ['methodCount ' ], 2 ) . $ resetColor . ' ' ;
291+
292+ if ($ hasBranchCoverage ) {
293+ $ output .= ' ' . $ pathsColor . 'Paths: ' . $ this ->printCoverageCounts ($ classInfo ['pathsCovered ' ], $ classInfo ['pathsCount ' ], 3 ) . $ resetColor . ' '
294+ . ' ' . $ branchesColor . 'Branches: ' . $ this ->printCoverageCounts ($ classInfo ['branchesCovered ' ], $ classInfo ['branchesCount ' ], 3 ) . $ resetColor . ' ' ;
295+ }
296+ $ output .= ' ' . $ linesColor . 'Lines: ' . $ this ->printCoverageCounts ($ classInfo ['statementsCovered ' ], $ classInfo ['statementCount ' ], 3 ) . $ resetColor ;
232297 }
233298 }
234299
0 commit comments