Skip to content

Commit

Permalink
- Merge [4621].
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 10, 2009
1 parent 8ce569d commit d8246e0
Showing 1 changed file with 99 additions and 99 deletions.
198 changes: 99 additions & 99 deletions PHPUnit/Util/Log/CodeCoverage/XML/Clover.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -108,23 +108,9 @@ public function process(PHPUnit_Framework_TestResult $result)
); );


foreach ($files as $filename => $data) { foreach ($files as $filename => $data) {
$fileStatistics = array( if (file_exists($filename)) {
'classes' => 0, $fileStatistics = array(
'methods' => 0, 'classes' => 0,
'coveredMethods' => 0,
'conditionals' => 0,
'coveredConditionals' => 0,
'statements' => 0,
'coveredStatements' => 0
);

$file = $document->createElement('file');
$file->setAttribute('name', $filename);

$lines = array();

foreach (PHPUnit_Util_File::getClassesInFile($filename) as $className => $_class) {
$classStatistics = array(
'methods' => 0, 'methods' => 0,
'coveredMethods' => 0, 'coveredMethods' => 0,
'conditionals' => 0, 'conditionals' => 0,
Expand All @@ -133,113 +119,127 @@ public function process(PHPUnit_Framework_TestResult $result)
'coveredStatements' => 0 'coveredStatements' => 0
); );


foreach ($_class['methods'] as $methodName => $method) { $file = $document->createElement('file');
$classStatistics['methods']++; $file->setAttribute('name', $filename);


$methodCount = 0; $lines = array();


for ($i = $method['startLine']; $i <= $method['endLine']; $i++) { foreach (PHPUnit_Util_File::getClassesInFile($filename) as $className => $_class) {
$add = TRUE; $classStatistics = array(
$count = 0; 'methods' => 0,
'coveredMethods' => 0,
'conditionals' => 0,
'coveredConditionals' => 0,
'statements' => 0,
'coveredStatements' => 0
);


if (isset($files[$filename][$i])) { foreach ($_class['methods'] as $methodName => $method) {
if ($files[$filename][$i] != -2) { $classStatistics['methods']++;
$classStatistics['statements']++;
}


if (is_array($files[$filename][$i])) { $methodCount = 0;
$classStatistics['coveredStatements']++;
$count = count($files[$filename][$i]);
$classStatistics['coveredMethods']++;
}


else if ($files[$filename][$i] == -2) { for ($i = $method['startLine']; $i <= $method['endLine']; $i++) {
$add = TRUE;
$count = 0;

if (isset($files[$filename][$i])) {
if ($files[$filename][$i] != -2) {
$classStatistics['statements']++;
}

if (is_array($files[$filename][$i])) {
$classStatistics['coveredStatements']++;
$count = count($files[$filename][$i]);
$classStatistics['coveredMethods']++;
}

else if ($files[$filename][$i] == -2) {
$add = FALSE;
}
} else {
$add = FALSE; $add = FALSE;
} }
} else {
$add = FALSE;
}


$methodCount = max($methodCount, $count); $methodCount = max($methodCount, $count);


if ($add) { if ($add) {
$lines[$i] = array( $lines[$i] = array(
'count' => $count, 'count' => $count,
'type' => 'stmt' 'type' => 'stmt'
); );
}
} }

$lines[$method['startLine']] = array(
'count' => $methodCount,
'type' => 'method'
);
} }


$lines[$method['startLine']] = array( $packageInformation = PHPUnit_Util_Class::getPackageInformation(
'count' => $methodCount, $className, $_class['docComment']
'type' => 'method'
); );
}


$packageInformation = PHPUnit_Util_Class::getPackageInformation( if (!empty($packageInformation['namespace'])) {
$className, $_class['docComment'] $namespace = $packageInformation['namespace'];
); } else {
$namespace = 'global';
}


if (!empty($packageInformation['namespace'])) { $class = $document->createElement('class');
$namespace = $packageInformation['namespace']; $class->setAttribute('name', $className);
} else { $class->setAttribute('namespace', $namespace);
$namespace = 'global';
}


$class = $document->createElement('class'); if (!empty($packageInformation['fullPackage'])) {
$class->setAttribute('name', $className); $class->setAttribute('fullPackage', $packageInformation['fullPackage']);
$class->setAttribute('namespace', $namespace); }


if (!empty($packageInformation['fullPackage'])) { if (!empty($packageInformation['category'])) {
$class->setAttribute('fullPackage', $packageInformation['fullPackage']); $class->setAttribute('category', $packageInformation['category']);
} }


if (!empty($packageInformation['category'])) { if (!empty($packageInformation['package'])) {
$class->setAttribute('category', $packageInformation['category']); $class->setAttribute('package', $packageInformation['package']);
} }


if (!empty($packageInformation['package'])) { if (!empty($packageInformation['subpackage'])) {
$class->setAttribute('package', $packageInformation['package']); $class->setAttribute('subpackage', $packageInformation['subpackage']);
} }


if (!empty($packageInformation['subpackage'])) { $file->appendChild($class);
$class->setAttribute('subpackage', $packageInformation['subpackage']);
$metrics = $document->createElement('metrics');
$metrics->setAttribute('methods', $classStatistics['methods']);
$metrics->setAttribute('coveredmethods', $classStatistics['coveredMethods']);
//$metrics->setAttribute('conditionals', $classStatistics['conditionals']);
//$metrics->setAttribute('coveredconditionals', $classStatistics['coveredConditionals']);
$metrics->setAttribute('statements', $classStatistics['statements']);
$metrics->setAttribute('coveredstatements', $classStatistics['coveredStatements']);
$metrics->setAttribute('elements', $classStatistics['conditionals'] + $classStatistics['statements'] + $classStatistics['methods']);
$metrics->setAttribute('coveredelements', $classStatistics['coveredConditionals'] + $classStatistics['coveredStatements'] + $classStatistics['coveredMethods']);
$class->appendChild($metrics);

$fileStatistics['methods'] += $classStatistics['methods'];
$fileStatistics['coveredMethods'] += $classStatistics['coveredMethods'];
$fileStatistics['conditionals'] += $classStatistics['conditionals'];
$fileStatistics['coveredConditionals'] += $classStatistics['coveredConditionals'];
$fileStatistics['statements'] += $classStatistics['statements'];
$fileStatistics['coveredStatements'] += $classStatistics['coveredStatements'];
$fileStatistics['classes']++;
} }


$file->appendChild($class); ksort($lines);


$metrics = $document->createElement('metrics'); foreach ($lines as $_line => $_data) {
$metrics->setAttribute('methods', $classStatistics['methods']); $line = $document->createElement('line');
$metrics->setAttribute('coveredmethods', $classStatistics['coveredMethods']); $line->setAttribute('num', $_line);
//$metrics->setAttribute('conditionals', $classStatistics['conditionals']); $line->setAttribute('type', $_data['type']);
//$metrics->setAttribute('coveredconditionals', $classStatistics['coveredConditionals']); $line->setAttribute('count', $_data['count']);
$metrics->setAttribute('statements', $classStatistics['statements']);
$metrics->setAttribute('coveredstatements', $classStatistics['coveredStatements']);
$metrics->setAttribute('elements', $classStatistics['conditionals'] + $classStatistics['statements'] + $classStatistics['methods']);
$metrics->setAttribute('coveredelements', $classStatistics['coveredConditionals'] + $classStatistics['coveredStatements'] + $classStatistics['coveredMethods']);
$class->appendChild($metrics);

$fileStatistics['methods'] += $classStatistics['methods'];
$fileStatistics['coveredMethods'] += $classStatistics['coveredMethods'];
$fileStatistics['conditionals'] += $classStatistics['conditionals'];
$fileStatistics['coveredConditionals'] += $classStatistics['coveredConditionals'];
$fileStatistics['statements'] += $classStatistics['statements'];
$fileStatistics['coveredStatements'] += $classStatistics['coveredStatements'];
$fileStatistics['classes']++;
}

ksort($lines);

foreach ($lines as $_line => $_data) {
$line = $document->createElement('line');
$line->setAttribute('num', $_line);
$line->setAttribute('type', $_data['type']);
$line->setAttribute('count', $_data['count']);


$file->appendChild($line); $file->appendChild($line);
} }


if (file_exists($filename)) {
$count = PHPUnit_Util_File::countLines($filename); $count = PHPUnit_Util_File::countLines($filename);


$metrics = $document->createElement('metrics'); $metrics = $document->createElement('metrics');
Expand Down

0 comments on commit d8246e0

Please sign in to comment.