@@ -351,6 +351,8 @@ public function getNumTestedFunctions()
351351 */
352352 protected function calculateStatistics ()
353353 {
354+ $ classStack = $ functionStack = [];
355+
354356 if ($ this ->cacheTokens ) {
355357 $ tokens = PHP_Token_Stream_CachingFactory::get ($ this ->getPath ());
356358 } else {
@@ -367,6 +369,10 @@ protected function calculateStatistics()
367369 if (isset ($ this ->startLines [$ lineNumber ])) {
368370 // Start line of a class.
369371 if (isset ($ this ->startLines [$ lineNumber ]['className ' ])) {
372+ if (isset ($ currentClass )) {
373+ $ classStack [] = &$ currentClass ;
374+ }
375+
370376 $ currentClass = &$ this ->startLines [$ lineNumber ];
371377 } // Start line of a trait.
372378 elseif (isset ($ this ->startLines [$ lineNumber ]['traitName ' ])) {
@@ -376,6 +382,10 @@ protected function calculateStatistics()
376382 $ currentMethod = &$ this ->startLines [$ lineNumber ];
377383 } // Start line of a function.
378384 elseif (isset ($ this ->startLines [$ lineNumber ]['functionName ' ])) {
385+ if (isset ($ currentFunction )) {
386+ $ functionStack [] = &$ currentFunction ;
387+ }
388+
379389 $ currentFunction = &$ this ->startLines [$ lineNumber ];
380390 }
381391 }
@@ -424,6 +434,13 @@ protected function calculateStatistics()
424434 // End line of a class.
425435 if (isset ($ this ->endLines [$ lineNumber ]['className ' ])) {
426436 unset($ currentClass );
437+
438+ if ($ classStack ) {
439+ end ($ classStack );
440+ $ key = key ($ classStack );
441+ $ currentClass = &$ classStack [$ key ];
442+ unset($ classStack [$ key ]);
443+ }
427444 } // End line of a trait.
428445 elseif (isset ($ this ->endLines [$ lineNumber ]['traitName ' ])) {
429446 unset($ currentTrait );
@@ -433,6 +450,13 @@ protected function calculateStatistics()
433450 } // End line of a function.
434451 elseif (isset ($ this ->endLines [$ lineNumber ]['functionName ' ])) {
435452 unset($ currentFunction );
453+
454+ if ($ functionStack ) {
455+ end ($ functionStack );
456+ $ key = key ($ functionStack );
457+ $ currentFunction = &$ functionStack [$ key ];
458+ unset($ functionsStack [$ key ]);
459+ }
436460 }
437461 }
438462 }
0 commit comments