@@ -441,95 +441,90 @@ private function calculateStatistics(): void
441441
442442 foreach ($ this ->traits as &$ trait ) {
443443 foreach ($ trait ['methods ' ] as &$ method ) {
444- if ($ method ['executableLines ' ] > 0 ) {
445- $ method ['coverage ' ] = ($ method ['executedLines ' ] /
446- $ method ['executableLines ' ]) * 100 ;
447- } else {
448- $ method ['coverage ' ] = 100 ;
449- }
444+ $ methodLineCoverage = $ method ['executableLines ' ] ? ($ method ['executedLines ' ] / $ method ['executableLines ' ]) * 100 : 100 ;
445+ $ methodBranchCoverage = $ method ['executableBranches ' ] ? ($ method ['executedBranches ' ] / $ method ['executableBranches ' ]) * 100 : 0 ;
446+ $ methodPathCoverage = $ method ['executablePaths ' ] ? ($ method ['executedPaths ' ] / $ method ['executablePaths ' ]) * 100 : 0 ;
447+
448+ $ method ['coverage ' ] = $ methodBranchCoverage ?: $ methodLineCoverage ;
450449
451450 $ method ['crap ' ] = $ this ->crap (
452451 $ method ['ccn ' ],
453- $ method [ ' coverage ' ]
452+ $ methodPathCoverage ?: $ methodLineCoverage
454453 );
455454
456455 $ trait ['ccn ' ] += $ method ['ccn ' ];
457456 }
458457
459458 unset($ method );
460459
461- if ( $ trait ['executableLines ' ] > 0 ) {
462- $ trait ['coverage ' ] = ($ trait ['executedLines ' ] /
463- $ trait ['executableLines ' ]) * 100 ;
460+ $ traitLineCoverage = $ trait ['executableLines ' ] ? ( $ trait [ ' executedLines ' ] / $ trait [ ' executableLines ' ]) * 100 : 100 ;
461+ $ traitBranchCoverage = $ trait ['executableBranches ' ] ? ($ trait ['executedBranches ' ] / $ trait [ ' executableBranches ' ]) * 100 : 0 ;
462+ $ traitPathCoverage = $ trait [ ' executablePaths ' ] ? ( $ trait [ ' executedPaths ' ] / $ trait ['executablePaths ' ]) * 100 : 0 ;
464463
465- if ($ trait ['coverage ' ] === 100 ) {
466- $ this ->numTestedClasses ++;
467- }
468- } else {
469- $ trait ['coverage ' ] = 100 ;
464+ $ trait ['coverage ' ] = $ traitBranchCoverage ?: $ traitLineCoverage ;
465+
466+ if ($ trait ['executableLines ' ] > 0 && $ trait ['coverage ' ] === 100 ) {
467+ $ this ->numTestedClasses ++;
470468 }
471469
472470 $ trait ['crap ' ] = $ this ->crap (
473471 $ trait ['ccn ' ],
474- $ trait [ ' coverage ' ]
472+ $ traitPathCoverage ?: $ traitLineCoverage
475473 );
476474 }
477475
478476 unset($ trait );
479477
480478 foreach ($ this ->classes as &$ class ) {
481479 foreach ($ class ['methods ' ] as &$ method ) {
482- if ($ method ['executableLines ' ] > 0 ) {
483- $ method ['coverage ' ] = ($ method ['executedLines ' ] /
484- $ method ['executableLines ' ]) * 100 ;
485- } else {
486- $ method ['coverage ' ] = 100 ;
487- }
480+ $ methodLineCoverage = $ method ['executableLines ' ] ? ($ method ['executedLines ' ] / $ method ['executableLines ' ]) * 100 : 100 ;
481+ $ methodBranchCoverage = $ method ['executableBranches ' ] ? ($ method ['executedBranches ' ] / $ method ['executableBranches ' ]) * 100 : 0 ;
482+ $ methodPathCoverage = $ method ['executablePaths ' ] ? ($ method ['executedPaths ' ] / $ method ['executablePaths ' ]) * 100 : 0 ;
483+
484+ $ method ['coverage ' ] = $ methodBranchCoverage ?: $ methodLineCoverage ;
488485
489486 $ method ['crap ' ] = $ this ->crap (
490487 $ method ['ccn ' ],
491- $ method [ ' coverage ' ]
488+ $ methodPathCoverage ?: $ methodLineCoverage
492489 );
493490
494491 $ class ['ccn ' ] += $ method ['ccn ' ];
495492 }
496493
497494 unset($ method );
498495
499- if ( $ class ['executableLines ' ] > 0 ) {
500- $ class ['coverage ' ] = ($ class ['executedLines ' ] /
501- $ class ['executableLines ' ]) * 100 ;
496+ $ classLineCoverage = $ class ['executableLines ' ] ? ( $ class [ ' executedLines ' ] / $ class [ ' executableLines ' ]) * 100 : 100 ;
497+ $ classBranchCoverage = $ class ['executableBranches ' ] ? ($ class ['executedBranches ' ] / $ class [ ' executableBranches ' ]) * 100 : 0 ;
498+ $ classPathCoverage = $ class [ ' executablePaths ' ] ? ( $ class [ ' executedPaths ' ] / $ class ['executablePaths ' ]) * 100 : 0 ;
502499
503- if ($ class ['coverage ' ] === 100 ) {
504- $ this ->numTestedClasses ++;
505- }
506- } else {
507- $ class ['coverage ' ] = 100 ;
500+ $ class ['coverage ' ] = $ classBranchCoverage ?: $ classLineCoverage ;
501+
502+ if ($ class ['executableLines ' ] > 0 && $ class ['coverage ' ] === 100 ) {
503+ $ this ->numTestedClasses ++;
508504 }
509505
510506 $ class ['crap ' ] = $ this ->crap (
511507 $ class ['ccn ' ],
512- $ class [ ' coverage ' ]
508+ $ classPathCoverage ?: $ classLineCoverage
513509 );
514510 }
515511
516512 unset($ class );
517513
518514 foreach ($ this ->functions as &$ function ) {
519- if ($ function ['executableLines ' ] > 0 ) {
520- $ function ['coverage ' ] = ($ function ['executedLines ' ] /
521- $ function ['executableLines ' ]) * 100 ;
522- } else {
523- $ function ['coverage ' ] = 100 ;
524- }
515+ $ functionLineCoverage = $ function ['executableLines ' ] ? ($ function ['executedLines ' ] / $ function ['executableLines ' ]) * 100 : 100 ;
516+ $ functionBranchCoverage = $ function ['executableBranches ' ] ? ($ function ['executedBranches ' ] / $ function ['executableBranches ' ]) * 100 : 0 ;
517+ $ functionPathCoverage = $ function ['executablePaths ' ] ? ($ function ['executedPaths ' ] / $ function ['executablePaths ' ]) * 100 : 0 ;
518+
519+ $ function ['coverage ' ] = $ functionBranchCoverage ?: $ functionLineCoverage ;
525520
526521 if ($ function ['coverage ' ] === 100 ) {
527522 $ this ->numTestedFunctions ++;
528523 }
529524
530525 $ function ['crap ' ] = $ this ->crap (
531526 $ function ['ccn ' ],
532- $ function [ ' coverage ' ]
527+ $ functionPathCoverage ?: $ functionLineCoverage
533528 );
534529 }
535530 }
0 commit comments