@@ -420,14 +420,24 @@ protected function calculateStatistics()
420420 for ($ lineNumber = 1 ; $ lineNumber <= $ this ->linesOfCode ['loc ' ]; $ lineNumber ++) {
421421 if (isset ($ this ->startLines [$ lineNumber ])) {
422422 // Start line of a class.
423- if (isset ($ this ->startLines [$ lineNumber ]['methods ' ])) {
423+ if (isset ($ this ->startLines [$ lineNumber ]['className ' ])) {
424424 $ currentClass = &$ this ->startLines [$ lineNumber ];
425425 }
426426
427+ // Start line of a trait.
428+ else if (isset ($ this ->startLines [$ lineNumber ]['traitName ' ])) {
429+ $ currentTrait = &$ this ->startLines [$ lineNumber ];
430+ }
431+
427432 // Start line of a method.
428- else {
433+ else if ( isset ( $ this -> startLines [ $ lineNumber ][ ' methodName ' ])) {
429434 $ currentMethod = &$ this ->startLines [$ lineNumber ];
430435 }
436+
437+ // Start line of a function.
438+ else if (isset ($ this ->startLines [$ lineNumber ]['functionName ' ])) {
439+ $ currentFunction = &$ this ->startLines [$ lineNumber ];
440+ }
431441 }
432442
433443 if (!isset ($ this ->ignoredLines [$ lineNumber ]) &&
@@ -437,10 +447,18 @@ protected function calculateStatistics()
437447 $ currentClass ['executableLines ' ]++;
438448 }
439449
450+ if (isset ($ currentTrait )) {
451+ $ currentTrait ['executableLines ' ]++;
452+ }
453+
440454 if (isset ($ currentMethod )) {
441455 $ currentMethod ['executableLines ' ]++;
442456 }
443457
458+ if (isset ($ currentFunction )) {
459+ $ currentFunction ['executableLines ' ]++;
460+ }
461+
444462 $ this ->numExecutableLines ++;
445463
446464 if (count ($ this ->coverageData [$ lineNumber ]) > 0 ||
@@ -449,24 +467,42 @@ protected function calculateStatistics()
449467 $ currentClass ['executedLines ' ]++;
450468 }
451469
470+ if (isset ($ currentTrait )) {
471+ $ currentTrait ['executedLines ' ]++;
472+ }
473+
452474 if (isset ($ currentMethod )) {
453475 $ currentMethod ['executedLines ' ]++;
454476 }
455477
478+ if (isset ($ currentFunction )) {
479+ $ currentFunction ['executedLines ' ]++;
480+ }
481+
456482 $ this ->numExecutedLines ++;
457483 }
458484 }
459485
460486 if (isset ($ this ->endLines [$ lineNumber ])) {
461487 // End line of a class.
462- if (isset ($ this ->endLines [$ lineNumber ]['methods ' ])) {
488+ if (isset ($ this ->endLines [$ lineNumber ]['className ' ])) {
463489 unset($ currentClass );
464490 }
465491
492+ // End line of a trait.
493+ else if (isset ($ this ->endLines [$ lineNumber ]['traitName ' ])) {
494+ unset($ currentTrait );
495+ }
496+
466497 // End line of a method.
467- else {
498+ else if ( isset ( $ this -> endLines [ $ lineNumber ][ ' methodName ' ])) {
468499 unset($ currentMethod );
469500 }
501+
502+ // End line of a function.
503+ else if (isset ($ this ->endLines [$ lineNumber ]['functionName ' ])) {
504+ unset($ currentFunction );
505+ }
470506 }
471507 }
472508
@@ -547,6 +583,7 @@ protected function processClasses(PHP_Token_Stream $tokens)
547583
548584 foreach ($ classes as $ className => $ class ) {
549585 $ this ->classes [$ className ] = array (
586+ 'className ' => $ className ,
550587 'methods ' => array (),
551588 'startLine ' => $ class ['startLine ' ],
552589 'executableLines ' => 0 ,
@@ -563,6 +600,7 @@ protected function processClasses(PHP_Token_Stream $tokens)
563600
564601 foreach ($ class ['methods ' ] as $ methodName => $ method ) {
565602 $ this ->classes [$ className ]['methods ' ][$ methodName ] = array (
603+ 'methodName ' => $ methodName ,
566604 'signature ' => $ method ['signature ' ],
567605 'startLine ' => $ method ['startLine ' ],
568606 'endLine ' => $ method ['endLine ' ],
@@ -592,6 +630,7 @@ protected function processTraits(PHP_Token_Stream $tokens)
592630
593631 foreach ($ traits as $ traitName => $ trait ) {
594632 $ this ->traits [$ traitName ] = array (
633+ 'traitName ' => $ traitName ,
595634 'methods ' => array (),
596635 'startLine ' => $ trait ['startLine ' ],
597636 'executableLines ' => 0 ,
@@ -608,6 +647,7 @@ protected function processTraits(PHP_Token_Stream $tokens)
608647
609648 foreach ($ trait ['methods ' ] as $ methodName => $ method ) {
610649 $ this ->traits [$ traitName ]['methods ' ][$ methodName ] = array (
650+ 'methodName ' => $ methodName ,
611651 'signature ' => $ method ['signature ' ],
612652 'startLine ' => $ method ['startLine ' ],
613653 'executableLines ' => 0 ,
@@ -636,11 +676,14 @@ protected function processFunctions(PHP_Token_Stream $tokens)
636676
637677 foreach ($ functions as $ functionName => $ function ) {
638678 $ this ->functions [$ functionName ] = array (
679+ 'functionName ' => $ functionName ,
639680 'signature ' => $ function ['signature ' ],
640681 'startLine ' => $ function ['startLine ' ],
641682 'executableLines ' => 0 ,
642683 'executedLines ' => 0 ,
643684 'ccn ' => $ function ['ccn ' ],
685+ 'coverage ' => 0 ,
686+ 'crap ' => 0 ,
644687 'link ' => $ link . $ function ['startLine ' ]
645688 );
646689
0 commit comments