Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/clover' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
holyshared committed Apr 25, 2015
2 parents d6b2acd + 00d597a commit fa2d4f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 45 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"guzzlehttp/guzzle": "~5.2",
"gitonomy/gitlib": "~0.1",
"yosymfony/toml": "~0.3",
"zendframework/zend-dom": "~2.4",
"symfony/dom-crawler": "~2.6",
"symfony/css-selector": "~2.6",
"zendframework/zend-config": "~2.4",
"zendframework/zend-console": "~2.4",
"eloquent/pathogen": "~0.6"
Expand Down
71 changes: 27 additions & 44 deletions src/report/parser/CloverReportParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
use coverallskit\entity\SourceFile;
use coverallskit\entity\collection\SourceFileCollection;
use coverallskit\entity\CoverageResult;
use Zend\Dom\Query;
use Zend\Dom\NodeList;
use Symfony\Component\DomCrawler\Crawler;
use coverallskit\exception\ExceptionCollection;
use coverallskit\exception\LineOutOfRangeException;
use DOMElement;


/**
Expand All @@ -28,11 +26,10 @@
*/
class CloverReportParser implements ReportParser
{

/**
* @var string
* @var \Symfony\Component\DomCrawler\Crawler
*/
private $reportContent;
private $crawler;

/**
* @var \coverallskit\entity\SourceFile
Expand All @@ -59,59 +56,42 @@ class CloverReportParser implements ReportParser
*/
private $reportParseErrors;


public function __construct()
{
$this->crawler = new Crawler();
$this->sourceCollection = new SourceFileCollection();
$this->reportParseErrors = new ExceptionCollection();
}


/**
* @param string $reportContent
* @return Result
*/
public function parse($reportContent)
{
$this->reportContent = $reportContent;
$this->crawler->addXmlContent($reportContent);
$fileNodes = $this->crawler->filter('file');

$files = $this->findFiles();
return $this->parseFileNodes($files);
return $this->parseFileNodes($fileNodes);
}

/**
* @return NodeList
*/
private function findFiles()
{
$query = new Query($this->reportContent);
return $query->execute('file');
}

/**
* @param string $fileName
* @return NodeList
*/
private function findCoverages($fileName)
{
$query = new Query($this->reportContent);
return $query->execute("file[name='$fileName'] line");
}

/**
* @param \Zend\Dom\NodeList $files
* @param Crawler $files
* @return Result
*/
private function parseFileNodes(NodeList $files)
private function parseFileNodes(Crawler $files)
{
foreach($files as $file) {
$fileName = (string) $file->getAttribute('name');
$fileNodeParser = function(Crawler $file) {
$fileName = $file->attr('name');

$this->source = new SourceFile($fileName);
$lines = $this->crawler->filter("file[name='$fileName'] line");

$lines = $this->findCoverages($fileName);
$this->parseLineNodes($lines);
}
};
$fileNodeParser->bind($this);

$files->each($fileNodeParser);

$result = new Result(
$this->sourceCollection,
Expand All @@ -122,16 +102,19 @@ private function parseFileNodes(NodeList $files)
}

/**
* @param \Zend\Dom\NodeList $lines
* @param Crawler $lines
*/
private function parseLineNodes(NodeList $lines)
private function parseLineNodes(Crawler $lines)
{
$this->coverages = $this->source->getEmptyCoverages();
$this->coveragesErrors = new ExceptionCollection($this->source->getName());

foreach ($lines as $line) {
$lineNodeParser = function(Crawler $line) {
$this->parseLine($line);
}
};
$lineNodeParser->bind($this);

$lines->each($lineNodeParser);

$this->source->addCoverages($this->coverages);
$this->sourceCollection->add($this->source);
Expand All @@ -140,12 +123,12 @@ private function parseLineNodes(NodeList $lines)
}

/**
* @param DOMElement $line
* @param Crawler $line
*/
private function parseLine(DOMElement $line)
private function parseLine(Crawler $line)
{
$lineNumber = (int) $line->getAttribute('num');
$executeCount = (int) $line->getAttribute('count');
$lineNumber = (int) $line->attr('num');
$executeCount = (int) $line->attr('count');

$analysisResult = ($executeCount >= 1)
? CoverageResult::EXECUTED : CoverageResult::UNUSED;
Expand Down

0 comments on commit fa2d4f5

Please sign in to comment.