Skip to content

Commit

Permalink
Fix PmdDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Nov 16, 2014
1 parent d0b4690 commit 0339f59
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions Cli/Descriptor/PmdDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,34 @@ protected function describeAnalysis(Analysis $analysis, array $options = array()

$xml->appendChild($pmd);

foreach ($analysis->getViolations() as $violation) {
/**
* @var $violation \SensioLabs\Insight\Sdk\Model\Violation
*/
$filename = $violation->getResource();

$nodes = $xpath->query(sprintf('//file[@name="%s"]', $filename));

if ($nodes->length > 0) {
$node = $nodes->item(0);
} else {
$node = $xml->createElement('file');
$node->setAttribute('name', $filename);

$pmd->appendChild($node);
$violations = $analysis->getViolations();
if ($violations) {
foreach ($violations as $violation) {
/**
* @var $violation \SensioLabs\Insight\Sdk\Model\Violation
*/
$filename = $violation->getResource();

$nodes = $xpath->query(sprintf('//file[@name="%s"]', $filename));

if ($nodes->length > 0) {
$node = $nodes->item(0);
} else {
$node = $xml->createElement('file');
$node->setAttribute('name', $filename);

$pmd->appendChild($node);
}

$violationNode = $xml->createElement('violation', $violation->getMessage());
$node->appendChild($violationNode);

$violationNode->setAttribute('beginline', $violation->getLine());
$violationNode->setAttribute('endline', $violation->getLine());
$violationNode->setAttribute('rule', $violation->getTitle());
$violationNode->setAttribute('ruleset', $violation->getCategory());
$violationNode->setAttribute('priority', $this->getPriority($violation));
}

$violationNode = $xml->createElement('violation', $violation->getMessage());
$node->appendChild($violationNode);

$violationNode->setAttribute('beginline', $violation->getLine());
$violationNode->setAttribute('endline', $violation->getLine());
$violationNode->setAttribute('rule', $violation->getTitle());
$violationNode->setAttribute('ruleset', $violation->getCategory());
$violationNode->setAttribute('priority', $this->getPriority($violation));
}

$output->writeln($xml->saveXML());
Expand Down

0 comments on commit 0339f59

Please sign in to comment.