Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/CodeCoverage/Report/Node/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ public function getNumTestedFunctions()
*/
protected function calculateStatistics()
{
$classStack = $functionStack = array();

if ($this->cacheTokens) {
$tokens = PHP_Token_Stream_CachingFactory::get($this->getPath());
} else {
Expand All @@ -367,6 +369,10 @@ protected function calculateStatistics()
if (isset($this->startLines[$lineNumber])) {
// Start line of a class.
if (isset($this->startLines[$lineNumber]['className'])) {
if (isset($currentClass)) {
$classStack[] = &$currentClass;
}

$currentClass = &$this->startLines[$lineNumber];
} // Start line of a trait.
elseif (isset($this->startLines[$lineNumber]['traitName'])) {
Expand All @@ -376,12 +382,15 @@ protected function calculateStatistics()
$currentMethod = &$this->startLines[$lineNumber];
} // Start line of a function.
elseif (isset($this->startLines[$lineNumber]['functionName'])) {
if (isset($currentFunction)) {
$functionStack[] = &$currentFunction;
}

$currentFunction = &$this->startLines[$lineNumber];
}
}

if (isset($this->coverageData[$lineNumber]) &&
$this->coverageData[$lineNumber] !== null) {
if (isset($this->coverageData[$lineNumber])) {
if (isset($currentClass)) {
$currentClass['executableLines']++;
}
Expand Down Expand Up @@ -425,6 +434,13 @@ protected function calculateStatistics()
// End line of a class.
if (isset($this->endLines[$lineNumber]['className'])) {
unset($currentClass);

if ($classStack) {
end($classStack);
$key = key($classStack);
$currentClass = &$classStack[$key];
unset($classStack[$key]);
}
} // End line of a trait.
elseif (isset($this->endLines[$lineNumber]['traitName'])) {
unset($currentTrait);
Expand All @@ -434,6 +450,13 @@ protected function calculateStatistics()
} // End line of a function.
elseif (isset($this->endLines[$lineNumber]['functionName'])) {
unset($currentFunction);

if ($functionStack) {
end($functionStack);
$key = key($functionStack);
$currentFunction = &$functionStack[$key];
unset($functionsStack[$key]);
}
}
}
}
Expand Down