@@ -35,6 +35,16 @@ class PHP_CodeCoverage_Report_Node_File extends PHP_CodeCoverage_Report_Node
35
35
*/
36
36
protected $ numExecutedLines = 0 ;
37
37
38
+ /**
39
+ * @var int
40
+ */
41
+ protected $ numExecutablePaths = 0 ;
42
+
43
+ /**
44
+ * @var int
45
+ */
46
+ protected $ numExecutedPaths = 0 ;
47
+
38
48
/**
39
49
* @var array
40
50
*/
@@ -213,6 +223,26 @@ public function getNumExecutedLines()
213
223
return $ this ->numExecutedLines ;
214
224
}
215
225
226
+ /**
227
+ * Returns the number of executable paths.
228
+ *
229
+ * @return int
230
+ */
231
+ public function getNumExecutablePaths ()
232
+ {
233
+ return $ this ->numExecutablePaths ;
234
+ }
235
+
236
+ /**
237
+ * Returns the number of executed paths.
238
+ *
239
+ * @return int
240
+ */
241
+ public function getNumExecutedPaths ()
242
+ {
243
+ return $ this ->numExecutedPaths ;
244
+ }
245
+
216
246
/**
217
247
* Returns the number of classes.
218
248
*
@@ -461,72 +491,25 @@ protected function calculateStatistics()
461
491
}
462
492
}
463
493
464
- foreach ($ this ->traits as &$ trait ) {
465
- foreach ($ trait ['methods ' ] as &$ method ) {
466
- if ($ method ['executableLines ' ] > 0 ) {
467
- $ method ['coverage ' ] = ($ method ['executedLines ' ] /
468
- $ method ['executableLines ' ]) * 100 ;
469
- } else {
470
- $ method ['coverage ' ] = 100 ;
471
- }
472
-
473
- $ method ['crap ' ] = $ this ->crap (
474
- $ method ['ccn ' ],
475
- $ method ['coverage ' ]
476
- );
494
+ foreach ($ this ->functions as &$ function ) {
495
+ if (isset ($ this ->coverageData ['paths ' ][$ function ['functionName ' ]])) {
496
+ $ functionPaths = $ this ->coverageData ['paths ' ][$ function ['functionName ' ]];
497
+ $ this ->calcPathsAggregate ($ functionPaths , $ numExecutablePaths , $ numExecutedPaths );
477
498
478
- $ trait ['ccn ' ] += $ method ['ccn ' ];
479
- }
480
-
481
- if ($ trait ['executableLines ' ] > 0 ) {
482
- $ trait ['coverage ' ] = ($ trait ['executedLines ' ] /
483
- $ trait ['executableLines ' ]) * 100 ;
484
- } else {
485
- $ trait ['coverage ' ] = 100 ;
486
- }
499
+ $ function ['executablePaths ' ] = $ numExecutablePaths ;
500
+ $ this ->numExecutablePaths += $ numExecutablePaths ;
487
501
488
- if ( $ trait [ ' coverage ' ] == 100 ) {
489
- $ this ->numTestedClasses ++ ;
502
+ $ function [ ' executedPaths ' ] = $ numExecutedPaths ;
503
+ $ this ->numExecutedPaths += $ numExecutedPaths ;
490
504
}
505
+ }
491
506
492
- $ trait ['crap ' ] = $ this ->crap (
493
- $ trait ['ccn ' ],
494
- $ trait ['coverage ' ]
495
- );
507
+ foreach ($ this ->traits as &$ trait ) {
508
+ $ this ->calcAndApplyClassAggregate ($ trait , $ trait ['traitName ' ]);
496
509
}
497
510
498
511
foreach ($ this ->classes as &$ class ) {
499
- foreach ($ class ['methods ' ] as &$ method ) {
500
- if ($ method ['executableLines ' ] > 0 ) {
501
- $ method ['coverage ' ] = ($ method ['executedLines ' ] /
502
- $ method ['executableLines ' ]) * 100 ;
503
- } else {
504
- $ method ['coverage ' ] = 100 ;
505
- }
506
-
507
- $ method ['crap ' ] = $ this ->crap (
508
- $ method ['ccn ' ],
509
- $ method ['coverage ' ]
510
- );
511
-
512
- $ class ['ccn ' ] += $ method ['ccn ' ];
513
- }
514
-
515
- if ($ class ['executableLines ' ] > 0 ) {
516
- $ class ['coverage ' ] = ($ class ['executedLines ' ] /
517
- $ class ['executableLines ' ]) * 100 ;
518
- } else {
519
- $ class ['coverage ' ] = 100 ;
520
- }
521
-
522
- if ($ class ['coverage ' ] == 100 ) {
523
- $ this ->numTestedClasses ++;
524
- }
525
-
526
- $ class ['crap ' ] = $ this ->crap (
527
- $ class ['ccn ' ],
528
- $ class ['coverage ' ]
529
- );
512
+ $ this ->calcAndApplyClassAggregate ($ class , $ class ['className ' ]);
530
513
}
531
514
}
532
515
@@ -547,6 +530,8 @@ protected function processClasses(PHP_Token_Stream $tokens)
547
530
'startLine ' => $ class ['startLine ' ],
548
531
'executableLines ' => 0 ,
549
532
'executedLines ' => 0 ,
533
+ 'executablePaths ' => 0 ,
534
+ 'executedPaths ' => 0 ,
550
535
'ccn ' => 0 ,
551
536
'coverage ' => 0 ,
552
537
'crap ' => 0 ,
@@ -583,6 +568,8 @@ protected function processTraits(PHP_Token_Stream $tokens)
583
568
'startLine ' => $ trait ['startLine ' ],
584
569
'executableLines ' => 0 ,
585
570
'executedLines ' => 0 ,
571
+ 'executablePaths ' => 0 ,
572
+ 'executedPaths ' => 0 ,
586
573
'ccn ' => 0 ,
587
574
'coverage ' => 0 ,
588
575
'crap ' => 0 ,
@@ -619,6 +606,8 @@ protected function processFunctions(PHP_Token_Stream $tokens)
619
606
'startLine ' => $ function ['startLine ' ],
620
607
'executableLines ' => 0 ,
621
608
'executedLines ' => 0 ,
609
+ 'executablePaths ' => 0 ,
610
+ 'executedPaths ' => 0 ,
622
611
'ccn ' => $ function ['ccn ' ],
623
612
'coverage ' => 0 ,
624
613
'crap ' => 0 ,
@@ -672,10 +661,73 @@ private function newMethod($methodName, array $method, $link)
672
661
'endLine ' => $ method ['endLine ' ],
673
662
'executableLines ' => 0 ,
674
663
'executedLines ' => 0 ,
664
+ 'executablePaths ' => 0 ,
665
+ 'executedPaths ' => 0 ,
675
666
'ccn ' => $ method ['ccn ' ],
676
667
'coverage ' => 0 ,
677
668
'crap ' => 0 ,
678
669
'link ' => $ link . $ method ['startLine ' ],
679
670
];
680
671
}
672
+
673
+ /**
674
+ * @param string $paths
675
+ * @param int $functionExecutablePaths
676
+ * @param int $functionExecutedPaths
677
+ */
678
+ private function calcPathsAggregate ($ paths , &$ functionExecutablePaths , &$ functionExecutedPaths )
679
+ {
680
+ $ functionExecutablePaths = count ($ paths );
681
+ $ functionExecutedPaths = array_reduce (
682
+ $ paths ,
683
+ function ($ carry , $ value ) {
684
+ return ($ value ['hit ' ] > 0 ) ? $ carry + 1 : $ carry ;
685
+ },
686
+ 0
687
+ );
688
+ }
689
+
690
+ /**
691
+ * @param array $classOrTrait
692
+ * @param string $classOrTraitName
693
+ */
694
+ protected function calcAndApplyClassAggregate (&$ classOrTrait , $ classOrTraitName )
695
+ {
696
+ foreach ($ classOrTrait ['methods ' ] as &$ method ) {
697
+ $ methodCoveragePath = $ classOrTraitName . '-> ' . $ method ['methodName ' ];
698
+ if (isset ($ this ->coverageData ['paths ' ][$ methodCoveragePath ])) {
699
+ $ methodPaths = $ this ->coverageData ['paths ' ][$ methodCoveragePath ];
700
+ $ this ->calcPathsAggregate ($ methodPaths , $ numExecutablePaths , $ numExecutedPaths );
701
+
702
+ $ method ['executablePaths ' ] = $ numExecutablePaths ;
703
+ $ classOrTrait ['executablePaths ' ] += $ numExecutablePaths ;
704
+ $ this ->numExecutablePaths += $ numExecutablePaths ;
705
+
706
+ $ method ['executedPaths ' ] = $ numExecutedPaths ;
707
+ $ classOrTrait ['executedPaths ' ] += $ numExecutedPaths ;
708
+ $ this ->numExecutedPaths += $ numExecutedPaths ;
709
+ }
710
+ if ($ method ['executableLines ' ] > 0 ) {
711
+ $ method ['coverage ' ] = ($ method ['executedLines ' ] / $ method ['executableLines ' ]) * 100 ;
712
+ } else {
713
+ $ method ['coverage ' ] = 100 ;
714
+ }
715
+
716
+ $ method ['crap ' ] = $ this ->crap ($ method ['ccn ' ], $ method ['coverage ' ]);
717
+
718
+ $ classOrTrait ['ccn ' ] += $ method ['ccn ' ];
719
+ }
720
+
721
+ if ($ classOrTrait ['executableLines ' ] > 0 ) {
722
+ $ classOrTrait ['coverage ' ] = ($ classOrTrait ['executedLines ' ] / $ classOrTrait ['executableLines ' ]) * 100 ;
723
+ } else {
724
+ $ classOrTrait ['coverage ' ] = 100 ;
725
+ }
726
+
727
+ if ($ classOrTrait ['coverage ' ] == 100 ) {
728
+ $ this ->numTestedClasses ++;
729
+ }
730
+
731
+ $ classOrTrait ['crap ' ] = $ this ->crap ($ classOrTrait ['ccn ' ], $ classOrTrait ['coverage ' ]);
732
+ }
681
733
}
0 commit comments