Example #1
0
 /**
  * @inheritdoc
  */
 public function terminate(ResultCollection $collection, ResultCollection $groupedResults)
 {
     \Twig_Autoloader::register();
     $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../../../../../templates/html');
     $twig = new \Twig_Environment($loader, array('cache' => false));
     $twig->addExtension(new FormatingExtension($this->validator));
     $bound = $this->bound->calculate($collection);
     return $twig->render('summary/report.html.twig', array('keys' => array_keys(current($collection->asArray())), 'results' => $collection->asArray(), 'groupedResults' => $groupedResults, 'root' => $groupedResults->getIterator()->current(), 'relations' => $this->prepareDataRelations($collection), 'scores' => $collection->getScore()->all(), 'ruleSet' => $this->validator->getRuleSet(), 'bounds' => $bound, 'withOOP' => null !== $bound->getSum('instability')));
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function terminate(ResultCollection $collection, ResultCollection $groupedResults)
 {
     // root
     $xml = new \DOMDocument("1.0", "UTF-8");
     $xml->formatOutput = true;
     $root = $xml->createElement("pmd");
     $root->setAttribute('version', '@package_version@');
     $root->setAttribute('timestamp', date('c'));
     // violations
     foreach ($collection as $item) {
         $file = $xml->createElement('file');
         $file->setAttribute('name', realpath($item->getFilename()));
         $array = $item->asArray();
         $hasViolation = false;
         foreach ($array as $key => $value) {
             $result = $this->validator->validate($key, $value);
             if (Validator::GOOD !== $result && Validator::UNKNOWN !== $result) {
                 $hasViolation = true;
                 $violation = $xml->createElement('violation');
                 $violation->setAttribute('beginline', 1);
                 $violation->setAttribute('endline', $array['loc']);
                 $violation->setAttribute('rule', $key);
                 $violation->setAttribute('ruleset', $key);
                 $violation->setAttribute('externalInfoUrl', 'http://halleck45.github.io/PhpMetrics/documentation/index.html');
                 $violation->setAttribute('priority', $result == Validator::WARNING ? 3 : 1);
                 $violation->nodeValue = sprintf('the "%1$s" value (%2$s) of "%3$s" is incorrect. The configured %1$s threshold is %4$s', $key, $value, $item->getName(), implode(', ', $this->validator->getRuleSet()->getRule($key)));
                 $file->appendChild($violation);
             }
         }
         if ($hasViolation) {
             $root->appendChild($file);
         }
     }
     $xml->appendChild($root);
     return $xml->saveXML();
 }