diff --git a/Cli/Descriptor/PmdDescriptor.php b/Cli/Descriptor/PmdDescriptor.php index 81538a1..0aba393 100644 --- a/Cli/Descriptor/PmdDescriptor.php +++ b/Cli/Descriptor/PmdDescriptor.php @@ -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());