99 */
1010namespace SebastianBergmann \CodeCoverage \Report \Html ;
1111
12+ use SebastianBergmann \CodeCoverage \Data \ProcessedBranchCoverageData ;
13+ use SebastianBergmann \CodeCoverage \Data \ProcessedFunctionCoverageData ;
14+ use SebastianBergmann \CodeCoverage \Data \ProcessedPathCoverageData ;
1215use const ENT_COMPAT ;
1316use const ENT_HTML401 ;
1417use const ENT_SUBSTITUTE ;
@@ -607,18 +610,20 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
607610 ];
608611 }
609612
613+ /** @var ProcessedFunctionCoverageData $method */
610614 foreach ($ functionCoverageData as $ method ) {
611- foreach ($ method ['branches ' ] as $ branch ) {
612- foreach (range ($ branch ['line_start ' ], $ branch ['line_end ' ]) as $ line ) {
615+ /** @var ProcessedBranchCoverageData $branch */
616+ foreach ($ method ->branches as $ branch ) {
617+ foreach (range ($ branch ->line_start , $ branch ->line_end ) as $ line ) {
613618 if (!isset ($ lineData [$ line ])) { // blank line at end of file is sometimes included here
614619 continue ;
615620 }
616621
617622 $ lineData [$ line ]['includedInBranches ' ]++;
618623
619- if ($ branch[ ' hit ' ]) {
624+ if ($ branch-> hit !== [ ]) {
620625 $ lineData [$ line ]['includedInHitBranches ' ]++;
621- $ lineData [$ line ]['tests ' ] = array_unique (array_merge ($ lineData [$ line ]['tests ' ], $ branch[ ' hit ' ] ));
626+ $ lineData [$ line ]['tests ' ] = array_unique (array_merge ($ lineData [$ line ]['tests ' ], $ branch-> hit ));
622627 }
623628 }
624629 }
@@ -693,18 +698,20 @@ private function renderSourceWithPathCoverage(FileNode $node): string
693698 ];
694699 }
695700
701+ /** @var ProcessedFunctionCoverageData $method */
696702 foreach ($ functionCoverageData as $ method ) {
697- foreach ($ method ['paths ' ] as $ pathId => $ path ) {
698- foreach ($ path ['path ' ] as $ branchTaken ) {
699- foreach (range ($ method ['branches ' ][$ branchTaken ]['line_start ' ], $ method ['branches ' ][$ branchTaken ]['line_end ' ]) as $ line ) {
703+ /** @var ProcessedPathCoverageData $path */
704+ foreach ($ method ->paths as $ pathId => $ path ) {
705+ foreach ($ path ->path as $ branchTaken ) {
706+ foreach (range ($ method ->branches [$ branchTaken ]->line_start , $ method ->branches [$ branchTaken ]->line_end ) as $ line ) {
700707 if (!isset ($ lineData [$ line ])) {
701708 continue ;
702709 }
703710 $ lineData [$ line ]['includedInPaths ' ][] = $ pathId ;
704711
705- if ($ path[ ' hit ' ]) {
712+ if ($ path-> hit !== [ ]) {
706713 $ lineData [$ line ]['includedInHitPaths ' ][] = $ pathId ;
707- $ lineData [$ line ]['tests ' ] = array_unique (array_merge ($ lineData [$ line ]['tests ' ], $ path[ ' hit ' ] ));
714+ $ lineData [$ line ]['tests ' ] = array_unique (array_merge ($ lineData [$ line ]['tests ' ], $ path-> hit ));
708715 }
709716 }
710717 }
@@ -877,21 +884,18 @@ private function renderPathStructure(FileNode $node): string
877884
878885 ksort ($ coverageData );
879886
887+ /** @var ProcessedFunctionCoverageData $methodData */
880888 foreach ($ coverageData as $ methodName => $ methodData ) {
881- if (!$ methodData ['paths ' ]) {
882- continue ;
883- }
884-
885889 $ pathStructure = '' ;
886890
887- if (count ($ methodData[ ' paths ' ] ) > 100 ) {
888- $ pathStructure .= '<p> ' . count ($ methodData[ ' paths ' ] ) . ' is too many paths to sensibly render, consider refactoring your code to bring this number down.</p> ' ;
891+ if (count ($ methodData-> paths ) > 100 ) {
892+ $ pathStructure .= '<p> ' . count ($ methodData-> paths ) . ' is too many paths to sensibly render, consider refactoring your code to bring this number down.</p> ' ;
889893
890894 continue ;
891895 }
892896
893- foreach ($ methodData[ ' paths ' ] as $ path ) {
894- $ pathStructure .= $ this ->renderPathLines ($ path , $ methodData[ ' branches ' ] , $ codeLines , $ testData );
897+ foreach ($ methodData-> paths as $ path ) {
898+ $ pathStructure .= $ this ->renderPathLines ($ path , $ methodData-> branches , $ codeLines , $ testData );
895899 }
896900
897901 if ($ pathStructure !== '' ) {
@@ -906,24 +910,25 @@ private function renderPathStructure(FileNode $node): string
906910 }
907911
908912 /**
913+ * @param array<int, ProcessedBranchCoverageData> $branches
909914 * @param list<string> $codeLines
910915 */
911- private function renderPathLines (array $ path , array $ branches , array $ codeLines , array $ testData ): string
916+ private function renderPathLines (ProcessedPathCoverageData $ path , array $ branches , array $ codeLines , array $ testData ): string
912917 {
913918 $ linesTemplate = new Template ($ this ->templatePath . 'lines.html.dist ' , '{{ ' , '}} ' );
914919 $ singleLineTemplate = new Template ($ this ->templatePath . 'line.html.dist ' , '{{ ' , '}} ' );
915920
916921 $ lines = '' ;
917922 $ first = true ;
918923
919- foreach ($ path[ ' path ' ] as $ branchId ) {
924+ foreach ($ path-> path as $ branchId ) {
920925 if ($ first ) {
921926 $ first = false ;
922927 } else {
923928 $ lines .= ' <tr><td colspan="2"> </td></tr> ' . "\n" ;
924929 }
925930
926- $ branchLines = range ($ branches [$ branchId ][ ' line_start ' ] , $ branches [$ branchId ][ ' line_end ' ] );
931+ $ branchLines = range ($ branches [$ branchId ]-> line_start , $ branches [$ branchId ]-> line_end );
927932 sort ($ branchLines ); // sometimes end_line < start_line
928933
929934 /** @var int $line */
@@ -935,7 +940,7 @@ private function renderPathLines(array $path, array $branches, array $codeLines,
935940 $ popoverContent = '' ;
936941 $ popoverTitle = '' ;
937942
938- $ numTests = count ($ path[ ' hit ' ] );
943+ $ numTests = count ($ path-> hit );
939944
940945 if ($ numTests === 0 ) {
941946 $ trClass = 'danger ' ;
@@ -949,7 +954,7 @@ private function renderPathLines(array $path, array $branches, array $codeLines,
949954 $ popoverTitle = '1 test covers this path ' ;
950955 }
951956
952- foreach ($ path[ ' hit ' ] as $ test ) {
957+ foreach ($ path-> hit as $ test ) {
953958 if ($ lineCss === 'covered-by-large-tests ' && $ testData [$ test ]['size ' ] === 'medium ' ) {
954959 $ lineCss = 'covered-by-medium-tests ' ;
955960 } elseif ($ testData [$ test ]['size ' ] === 'small ' ) {
0 commit comments