lithium\test\filter\Coverage::analyze()
Overrides
lithium\test\Filter::analyze()
Analyzes code coverage results collected from XDebug, and performs coverage density analysis.
Parameters
-
object
$report
The report instance running this filter and aggregating results
-
array
$classes
A list of classes to analyze coverage on. By default, gets all defined subclasses of lithium\test\Unit which are currently in memory.
Returns
arrayReturns an array indexed by file and line, showing the number of instances each line was called.
Source
public static function analyze($report, array $classes = []) {
$data = static::collect($report->results['filters'][__CLASS__]);
$classes = $classes ?: array_filter(get_declared_classes(), function($class) use ($data) {
$unit = 'lithium\test\Unit';
return (!(is_subclass_of($class, $unit)) || array_key_exists($class, $data));
});
$classes = array_values(array_intersect((array) $classes, array_keys($data)));
$densities = $result = [];
foreach ($classes as $class) {
$classMap = [$class => Libraries::path($class)];
$densities += static::_density($data[$class], $classMap);
}
$executableLines = [];
if ($classes) {
$executableLines = array_combine($classes, array_map(
function($cls) { return Inspector::executable($cls, ['public' => false]); },
$classes
));
}
foreach ($densities as $class => $density) {
$executable = $executableLines[$class];
$covered = array_intersect(array_keys($density), $executable);
$uncovered = array_diff($executable, $covered);
if (count($executable)) {
$percentage = round(count($covered) / (count($executable) ?: 1), 4) * 100;
} else {
$percentage = 100;
}
$result[$class] = compact('class', 'executable', 'covered', 'uncovered', 'percentage');
}
$result = static::collectLines($result);
return $result;
}