for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace exussum12\CoverageChecker;
use XMLReader;
/**
* Class XMLReport
* Used for reading in a phpunit clover XML file
* @package exussum12\CoverageChecker
*/
class XMLReport implements FileChecker
{
* @var string
protected $file;
* @var array
protected $coveredLines;
* XMLReport constructor.
* @param string $file the path the to phpunit clover file
public function __construct($file)
$this->file = $file;
}
* {@inheritdoc}
public function getLines()
$this->coveredLines = [];
$reader = new XMLReader;
$reader->open($this->file);
$currentFile = '';
while ($reader->read()) {
if ((
$reader->name === "file" &&
$reader->nodeType == XMLReader::ELEMENT
)) {
$currentFile = $reader->getAttribute('name');
$this->coveredLines[$currentFile] = [];
$reader->name === "line" &&
$reader->getAttribute("type") == "stmt"
$this->coveredLines
[$currentFile]
[$reader->getAttribute('num')]
= (int) $reader->getAttribute("count");
return $this->coveredLines;
public function isValidLine($file, $line)
if (!isset($this->coveredLines[$file][$line])) {
return;
return $this->coveredLines[$file][$line] > 0;
public function handleNotFoundFile()
return null;
public static function getDescription()
return 'Parses text output in clover (xml) format designed for ' .
'phpunit but any tool which outputs in this format should work';