@@ -441,95 +441,90 @@ private function calculateStatistics(): void
441
441
442
442
foreach ($ this ->traits as &$ trait ) {
443
443
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 ;
450
449
451
450
$ method ['crap ' ] = $ this ->crap (
452
451
$ method ['ccn ' ],
453
- $ method [ ' coverage ' ]
452
+ $ methodPathCoverage ?: $ methodLineCoverage
454
453
);
455
454
456
455
$ trait ['ccn ' ] += $ method ['ccn ' ];
457
456
}
458
457
459
458
unset($ method );
460
459
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 ;
464
463
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 ++;
470
468
}
471
469
472
470
$ trait ['crap ' ] = $ this ->crap (
473
471
$ trait ['ccn ' ],
474
- $ trait [ ' coverage ' ]
472
+ $ traitPathCoverage ?: $ traitLineCoverage
475
473
);
476
474
}
477
475
478
476
unset($ trait );
479
477
480
478
foreach ($ this ->classes as &$ class ) {
481
479
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 ;
488
485
489
486
$ method ['crap ' ] = $ this ->crap (
490
487
$ method ['ccn ' ],
491
- $ method [ ' coverage ' ]
488
+ $ methodPathCoverage ?: $ methodLineCoverage
492
489
);
493
490
494
491
$ class ['ccn ' ] += $ method ['ccn ' ];
495
492
}
496
493
497
494
unset($ method );
498
495
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 ;
502
499
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 ++;
508
504
}
509
505
510
506
$ class ['crap ' ] = $ this ->crap (
511
507
$ class ['ccn ' ],
512
- $ class [ ' coverage ' ]
508
+ $ classPathCoverage ?: $ classLineCoverage
513
509
);
514
510
}
515
511
516
512
unset($ class );
517
513
518
514
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 ;
525
520
526
521
if ($ function ['coverage ' ] === 100 ) {
527
522
$ this ->numTestedFunctions ++;
528
523
}
529
524
530
525
$ function ['crap ' ] = $ this ->crap (
531
526
$ function ['ccn ' ],
532
- $ function [ ' coverage ' ]
527
+ $ functionPathCoverage ?: $ functionLineCoverage
533
528
);
534
529
}
535
530
}
0 commit comments