@@ -636,7 +636,8 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
636636 $ testData = $ node ->testData ();
637637 $ codeLines = $ this ->loadFile ($ node ->pathAsString ());
638638
639- $ lineData = [];
639+ $ lineData = [];
640+ $ branchStartData = [];
640641
641642 foreach (array_keys ($ codeLines ) as $ line ) {
642643 $ lineData [$ line + 1 ] = [
@@ -650,6 +651,20 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
650651 foreach ($ functionCoverageData as $ method ) {
651652 /** @var ProcessedBranchCoverageData $branch */
652653 foreach ($ method ->branches as $ branch ) {
654+ $ startLine = min ($ branch ->line_start , $ branch ->line_end );
655+
656+ if (isset ($ lineData [$ startLine ])) {
657+ if (!isset ($ branchStartData [$ startLine ])) {
658+ $ branchStartData [$ startLine ] = ['total ' => 0 , 'hit ' => 0 ];
659+ }
660+
661+ $ branchStartData [$ startLine ]['total ' ]++;
662+
663+ if ($ branch ->hit !== []) {
664+ $ branchStartData [$ startLine ]['hit ' ]++;
665+ }
666+ }
667+
653668 foreach (range ($ branch ->line_start , $ branch ->line_end ) as $ line ) {
654669 if (!isset ($ lineData [$ line ])) { // blank line at end of file is sometimes included here
655670 continue ;
@@ -673,6 +688,9 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
673688 $ trClass = '' ;
674689 $ popover = '' ;
675690
691+ $ coverageCount = '' ;
692+ $ coverageCountClass = 'coverage-count ' ;
693+
676694 if ($ lineData [$ i ]['includedInBranches ' ] > 0 ) {
677695 $ lineCss = 'success ' ;
678696
@@ -682,6 +700,10 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
682700 $ lineCss = 'warning ' ;
683701 }
684702
703+ if (isset ($ branchStartData [$ i ]) && $ branchStartData [$ i ]['total ' ] > 1 ) {
704+ $ coverageCount = $ branchStartData [$ i ]['hit ' ] . '/ ' . $ branchStartData [$ i ]['total ' ];
705+ }
706+
685707 $ popoverContent = '<ul> ' ;
686708
687709 if (count ($ lineData [$ i ]['tests ' ]) === 1 ) {
@@ -705,7 +727,7 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
705727 );
706728 }
707729
708- $ lines .= $ this ->renderLine ($ singleLineTemplate , $ i , $ line , $ trClass , $ popover );
730+ $ lines .= $ this ->renderLine ($ singleLineTemplate , $ i , $ line , $ trClass , $ popover, $ coverageCount , $ coverageCountClass );
709731
710732 $ i ++;
711733 }
@@ -761,6 +783,8 @@ private function renderSourceWithPathCoverage(FileNode $node): string
761783 foreach ($ codeLines as $ line ) {
762784 $ trClass = '' ;
763785 $ popover = '' ;
786+ $ coverageCount = '' ;
787+ $ coverageCountClass = 'coverage-count ' ;
764788 $ includedInPathsCount = count (array_unique ($ lineData [$ i ]['includedInPaths ' ]));
765789 $ includedInHitPathsCount = count (array_unique ($ lineData [$ i ]['includedInHitPaths ' ]));
766790
@@ -796,7 +820,7 @@ private function renderSourceWithPathCoverage(FileNode $node): string
796820 );
797821 }
798822
799- $ lines .= $ this ->renderLine ($ singleLineTemplate , $ i , $ line , $ trClass , $ popover );
823+ $ lines .= $ this ->renderLine ($ singleLineTemplate , $ i , $ line , $ trClass , $ popover, $ coverageCount , $ coverageCountClass );
800824
801825 $ i ++;
802826 }
@@ -971,14 +995,16 @@ private function renderPathStructure(FileNode $node): string
971995 return $ pathsTemplate ->render ();
972996 }
973997
974- private function renderLine (Template $ template , int $ lineNumber , string $ lineContent , string $ class , string $ popover ): string
998+ private function renderLine (Template $ template , int $ lineNumber , string $ lineContent , string $ class , string $ popover, string $ coverageCount = '' , string $ coverageCountClass = ' col-0 ' ): string
975999 {
9761000 $ template ->setVar (
9771001 [
978- 'lineNumber ' => (string ) $ lineNumber ,
979- 'lineContent ' => $ lineContent ,
980- 'class ' => $ class ,
981- 'popover ' => $ popover ,
1002+ 'lineNumber ' => (string ) $ lineNumber ,
1003+ 'lineContent ' => $ lineContent ,
1004+ 'class ' => $ class ,
1005+ 'popover ' => $ popover ,
1006+ 'coverageCount ' => $ coverageCount ,
1007+ 'coverageCountClass ' => $ coverageCountClass ,
9821008 ],
9831009 );
9841010
0 commit comments