@@ -638,7 +638,8 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
638638 $ testData = $ node ->testData ();
639639 $ codeLines = $ this ->loadFile ($ node ->pathAsString ());
640640
641- $ lineData = [];
641+ $ lineData = [];
642+ $ branchStartData = [];
642643
643644 foreach (array_keys ($ codeLines ) as $ line ) {
644645 $ lineData [$ line + 1 ] = [
@@ -652,6 +653,20 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
652653 foreach ($ functionCoverageData as $ method ) {
653654 /** @var ProcessedBranchCoverageData $branch */
654655 foreach ($ method ->branches as $ branch ) {
656+ $ startLine = min ($ branch ->line_start , $ branch ->line_end );
657+
658+ if (isset ($ lineData [$ startLine ])) {
659+ if (!isset ($ branchStartData [$ startLine ])) {
660+ $ branchStartData [$ startLine ] = ['total ' => 0 , 'hit ' => 0 ];
661+ }
662+
663+ $ branchStartData [$ startLine ]['total ' ]++;
664+
665+ if ($ branch ->hit !== []) {
666+ $ branchStartData [$ startLine ]['hit ' ]++;
667+ }
668+ }
669+
655670 foreach (range ($ branch ->line_start , $ branch ->line_end ) as $ line ) {
656671 if (!isset ($ lineData [$ line ])) { // blank line at end of file is sometimes included here
657672 continue ;
@@ -675,6 +690,9 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
675690 $ trClass = '' ;
676691 $ popover = '' ;
677692
693+ $ coverageCount = '' ;
694+ $ coverageCountClass = 'coverage-count ' ;
695+
678696 if ($ lineData [$ i ]['includedInBranches ' ] > 0 ) {
679697 $ lineCss = 'success ' ;
680698
@@ -684,6 +702,10 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
684702 $ lineCss = 'warning ' ;
685703 }
686704
705+ if (isset ($ branchStartData [$ i ]) && $ branchStartData [$ i ]['total ' ] > 1 ) {
706+ $ coverageCount = $ branchStartData [$ i ]['hit ' ] . '/ ' . $ branchStartData [$ i ]['total ' ];
707+ }
708+
687709 $ popoverContent = '<ul> ' ;
688710
689711 if (count ($ lineData [$ i ]['tests ' ]) === 1 ) {
@@ -707,7 +729,7 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
707729 );
708730 }
709731
710- $ lines .= $ this ->renderLine ($ singleLineTemplate , $ i , $ line , $ trClass , $ popover );
732+ $ lines .= $ this ->renderLine ($ singleLineTemplate , $ i , $ line , $ trClass , $ popover, $ coverageCount , $ coverageCountClass );
711733
712734 $ i ++;
713735 }
@@ -763,6 +785,8 @@ private function renderSourceWithPathCoverage(FileNode $node): string
763785 foreach ($ codeLines as $ line ) {
764786 $ trClass = '' ;
765787 $ popover = '' ;
788+ $ coverageCount = '' ;
789+ $ coverageCountClass = 'coverage-count ' ;
766790 $ includedInPathsCount = count (array_unique ($ lineData [$ i ]['includedInPaths ' ]));
767791 $ includedInHitPathsCount = count (array_unique ($ lineData [$ i ]['includedInHitPaths ' ]));
768792
@@ -798,7 +822,7 @@ private function renderSourceWithPathCoverage(FileNode $node): string
798822 );
799823 }
800824
801- $ lines .= $ this ->renderLine ($ singleLineTemplate , $ i , $ line , $ trClass , $ popover );
825+ $ lines .= $ this ->renderLine ($ singleLineTemplate , $ i , $ line , $ trClass , $ popover, $ coverageCount , $ coverageCountClass );
802826
803827 $ i ++;
804828 }
@@ -973,14 +997,16 @@ private function renderPathStructure(FileNode $node): string
973997 return $ pathsTemplate ->render ();
974998 }
975999
976- private function renderLine (Template $ template , int $ lineNumber , string $ lineContent , string $ class , string $ popover ): string
1000+ private function renderLine (Template $ template , int $ lineNumber , string $ lineContent , string $ class , string $ popover, string $ coverageCount = '' , string $ coverageCountClass = ' col-0 ' ): string
9771001 {
9781002 $ template ->setVar (
9791003 [
980- 'lineNumber ' => (string ) $ lineNumber ,
981- 'lineContent ' => $ lineContent ,
982- 'class ' => $ class ,
983- 'popover ' => $ popover ,
1004+ 'lineNumber ' => (string ) $ lineNumber ,
1005+ 'lineContent ' => $ lineContent ,
1006+ 'class ' => $ class ,
1007+ 'popover ' => $ popover ,
1008+ 'coverageCount ' => $ coverageCount ,
1009+ 'coverageCountClass ' => $ coverageCountClass ,
9841010 ],
9851011 );
9861012
0 commit comments