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 ;
@@ -603,18 +606,20 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
603606 ];
604607 }
605608
609+ /** @var ProcessedFunctionCoverageData $method */
606610 foreach ($ functionCoverageData as $ method ) {
607- foreach ($ method ['branches ' ] as $ branch ) {
608- foreach (range ($ branch ['line_start ' ], $ branch ['line_end ' ]) as $ line ) {
611+ /** @var ProcessedBranchCoverageData $branch */
612+ foreach ($ method ->branches as $ branch ) {
613+ foreach (range ($ branch ->line_start , $ branch ->line_end ) as $ line ) {
609614 if (!isset ($ lineData [$ line ])) { // blank line at end of file is sometimes included here
610615 continue ;
611616 }
612617
613618 $ lineData [$ line ]['includedInBranches ' ]++;
614619
615- if ($ branch[ ' hit ' ]) {
620+ if ($ branch-> hit !== [ ]) {
616621 $ lineData [$ line ]['includedInHitBranches ' ]++;
617- $ lineData [$ line ]['tests ' ] = array_unique (array_merge ($ lineData [$ line ]['tests ' ], $ branch[ ' hit ' ] ));
622+ $ lineData [$ line ]['tests ' ] = array_unique (array_merge ($ lineData [$ line ]['tests ' ], $ branch-> hit ));
618623 }
619624 }
620625 }
@@ -689,18 +694,20 @@ private function renderSourceWithPathCoverage(FileNode $node): string
689694 ];
690695 }
691696
697+ /** @var ProcessedFunctionCoverageData $method */
692698 foreach ($ functionCoverageData as $ method ) {
693- foreach ($ method ['paths ' ] as $ pathId => $ path ) {
694- foreach ($ path ['path ' ] as $ branchTaken ) {
695- foreach (range ($ method ['branches ' ][$ branchTaken ]['line_start ' ], $ method ['branches ' ][$ branchTaken ]['line_end ' ]) as $ line ) {
699+ /** @var ProcessedPathCoverageData $path */
700+ foreach ($ method ->paths as $ pathId => $ path ) {
701+ foreach ($ path ->path as $ branchTaken ) {
702+ foreach (range ($ method ->branches [$ branchTaken ]->line_start , $ method ->branches [$ branchTaken ]->line_end ) as $ line ) {
696703 if (!isset ($ lineData [$ line ])) {
697704 continue ;
698705 }
699706 $ lineData [$ line ]['includedInPaths ' ][] = $ pathId ;
700707
701- if ($ path[ ' hit ' ]) {
708+ if ($ path-> hit !== [ ]) {
702709 $ lineData [$ line ]['includedInHitPaths ' ][] = $ pathId ;
703- $ lineData [$ line ]['tests ' ] = array_unique (array_merge ($ lineData [$ line ]['tests ' ], $ path[ ' hit ' ] ));
710+ $ lineData [$ line ]['tests ' ] = array_unique (array_merge ($ lineData [$ line ]['tests ' ], $ path-> hit ));
704711 }
705712 }
706713 }
@@ -873,21 +880,18 @@ private function renderPathStructure(FileNode $node): string
873880
874881 ksort ($ coverageData );
875882
883+ /** @var ProcessedFunctionCoverageData $methodData */
876884 foreach ($ coverageData as $ methodName => $ methodData ) {
877- if (!$ methodData ['paths ' ]) {
878- continue ;
879- }
880-
881885 $ pathStructure = '' ;
882886
883- if (count ($ methodData[ ' paths ' ] ) > 100 ) {
884- $ pathStructure .= '<p> ' . count ($ methodData[ ' paths ' ] ) . ' is too many paths to sensibly render, consider refactoring your code to bring this number down.</p> ' ;
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> ' ;
885889
886890 continue ;
887891 }
888892
889- foreach ($ methodData[ ' paths ' ] as $ path ) {
890- $ pathStructure .= $ this ->renderPathLines ($ path , $ methodData[ ' branches ' ] , $ codeLines , $ testData );
893+ foreach ($ methodData-> paths as $ path ) {
894+ $ pathStructure .= $ this ->renderPathLines ($ path , $ methodData-> branches , $ codeLines , $ testData );
891895 }
892896
893897 if ($ pathStructure !== '' ) {
@@ -902,24 +906,25 @@ private function renderPathStructure(FileNode $node): string
902906 }
903907
904908 /**
909+ * @param array<int, ProcessedBranchCoverageData> $branches
905910 * @param list<string> $codeLines
906911 */
907- private function renderPathLines (array $ path , array $ branches , array $ codeLines , array $ testData ): string
912+ private function renderPathLines (ProcessedPathCoverageData $ path , array $ branches , array $ codeLines , array $ testData ): string
908913 {
909914 $ linesTemplate = new Template ($ this ->templatePath . 'lines.html.dist ' , '{{ ' , '}} ' );
910915 $ singleLineTemplate = new Template ($ this ->templatePath . 'line.html.dist ' , '{{ ' , '}} ' );
911916
912917 $ lines = '' ;
913918 $ first = true ;
914919
915- foreach ($ path[ ' path ' ] as $ branchId ) {
920+ foreach ($ path-> path as $ branchId ) {
916921 if ($ first ) {
917922 $ first = false ;
918923 } else {
919924 $ lines .= ' <tr><td colspan="2"> </td></tr> ' . "\n" ;
920925 }
921926
922- $ branchLines = range ($ branches [$ branchId ][ ' line_start ' ] , $ branches [$ branchId ][ ' line_end ' ] );
927+ $ branchLines = range ($ branches [$ branchId ]-> line_start , $ branches [$ branchId ]-> line_end );
923928 sort ($ branchLines ); // sometimes end_line < start_line
924929
925930 /** @var int $line */
@@ -931,7 +936,7 @@ private function renderPathLines(array $path, array $branches, array $codeLines,
931936 $ popoverContent = '' ;
932937 $ popoverTitle = '' ;
933938
934- $ numTests = count ($ path[ ' hit ' ] );
939+ $ numTests = count ($ path-> hit );
935940
936941 if ($ numTests === 0 ) {
937942 $ trClass = 'danger ' ;
@@ -945,7 +950,7 @@ private function renderPathLines(array $path, array $branches, array $codeLines,
945950 $ popoverTitle = '1 test covers this path ' ;
946951 }
947952
948- foreach ($ path[ ' hit ' ] as $ test ) {
953+ foreach ($ path-> hit as $ test ) {
949954 if ($ lineCss === 'covered-by-large-tests ' && $ testData [$ test ]['size ' ] === 'medium ' ) {
950955 $ lineCss = 'covered-by-medium-tests ' ;
951956 } elseif ($ testData [$ test ]['size ' ] === 'small ' ) {
0 commit comments