/** * @inheritdoc */ public function terminate(ResultCollection $collection, ResultCollection $groupedResults) { $text = 'digraph G {' . PHP_EOL . 'bgcolor=white;' . PHP_EOL . 'node [shape=circle, color=lightblue2, style=filled];'; $width = 300; foreach ($collection as $item) { // color $valid = $this->validator->validate('maintenabilityIndex', $item->getMaintenabilityIndex()->getMaintenabilityIndex()); switch ($valid) { case Validator::CRITICAL: $color = 'red'; break; case Validator::GOOD: $color = 'chartreuse4'; break; case Validator::WARNING: $color = 'gold1'; break; case Validator::UNKNOWN: $color = 'grey'; break; } // size $size = round($item->getMcCabe()->getCyclomaticComplexityNumber() * $width / 100); $text .= PHP_EOL . sprintf('"%1$s" [color=%2$s, tooltip="%3$s", width=%4$s, height=%4$s, label=""];', $item->getName(), $color, $item->getName(), $size, $size); } $text .= PHP_EOL . '}'; $chart = new Graphviz(); return $chart->getImage($text); }
/** * @dataProvider provideRuleset */ public function testICanValidateByRule($rule, $value, $expected) { $ruleSet = $this->getMock('\\Hal\\Application\\Rule\\RuleSet'); $ruleSet->expects($this->once())->method('getRule')->will($this->returnValue($rule)); $validator = new Validator($ruleSet); $result = $validator->validate('any', $value); $this->assertEquals($expected, $result); }
/** * @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'))); }
/** * Get style, according score * * @param string $key * @param double $value * @return string */ private function getStyle($key, $value) { $score = $this->validator->validate($key, $value); switch ($score) { case Validator::GOOD: return 'fg=green'; case Validator::WARNING: return 'bg=yellow;fg=black'; case Validator::CRITICAL: return 'bg=red;fg=white'; } return 'fg=white'; }
/** * @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(); }
/** * Check value according rule * * @param $key * @param $v * @return string */ public function rule($v, $key) { return $this->validator->validate($key, $v); }