/** * Closes the logger process and writes the output file. * * @return void */ public function close() { // Check for configured log file if ($this->logFile === null) { throw new PHP_Depend_Log_NoLogOutputException($this); } $metrics = $this->collectMetrics(); $proportions = $this->computeProportions($metrics); $svg = new DOMDocument('1.0', 'UTF-8'); $svg->load(dirname(__FILE__) . '/pyramid.svg'); $items = array_merge($metrics, $proportions); foreach ($items as $name => $value) { $svg->getElementById("pdepend.{$name}")->nodeValue = $value; if (($threshold = $this->computeThreshold($name, $value)) === null) { continue; } if (($color = $svg->getElementById("threshold.{$threshold}")) === null) { continue; } if (($rect = $svg->getElementById("rect.{$name}")) === null) { continue; } preg_match('/fill:(#[^;"]+)/', $color->getAttribute('style'), $match); $style = $rect->getAttribute('style'); $style = preg_replace('/fill:#[^;"]+/', "fill:{$match[1]}", $style); $rect->setAttribute('style', $style); } $temp = PHP_Depend_Util_FileUtil::getSysTempDir(); $temp .= '/' . uniqid('pdepend_') . '.svg'; $svg->save($temp); PHP_Depend_Util_ImageConvert::convert($temp, $this->logFile); // Remove temp file unlink($temp); }
/** * Closes the logger process and writes the output file. * * @return void * @throws PHP_Depend_Log_NoLogOutputException If the no log target exists. */ public function close() { // Check for configured log file if ($this->logFile === null) { throw new PHP_Depend_Log_NoLogOutputException($this); } $bias = 0.1; $svg = new DOMDocument('1.0', 'UTF-8'); $svg->load(dirname(__FILE__) . '/chart.svg'); $bad = $svg->getElementById('jdepend.bad'); $good = $svg->getElementById('jdepend.good'); $layer = $svg->getElementById('jdepend.layer'); $legendTemplate = $svg->getElementById('jdepend.legend'); $max = 0; $min = 0; $items = array(); foreach ($this->code as $package) { if (!$package->isUserDefined()) { continue; } $metrics = $this->analyzer->getStats($package); if (count($metrics) === 0) { continue; } $size = $metrics['cc'] + $metrics['ac']; if ($size > $max) { $max = $size; } else { if ($min === 0 || $size < $min) { $min = $size; } } $items[] = array('size' => $size, 'abstraction' => $metrics['a'], 'instability' => $metrics['i'], 'distance' => $metrics['d'], 'name' => $package->getName()); } $diff = ($max - $min) / 10; // Sort items by size usort($items, create_function('$a, $b', 'return ($a["size"] - $b["size"]);')); foreach ($items as $item) { if ($item['distance'] < $bias) { $ellipse = $good->cloneNode(true); } else { $ellipse = $bad->cloneNode(true); } $r = 15; if ($diff !== 0) { $r = 5 + ($item['size'] - $min) / $diff; } $a = $r / 15; $e = 50 - $r + $item['abstraction'] * 320; $f = 20 - $r + 190 - $item['instability'] * 190; $transform = "matrix({$a}, 0, 0, {$a}, {$e}, {$f})"; $ellipse->removeAttribute('xml:id'); $ellipse->setAttribute('id', uniqid('pdepend_')); $ellipse->setAttribute('title', $item['name']); $ellipse->setAttribute('transform', $transform); $layer->appendChild($ellipse); $result = preg_match('#\\\\([^\\\\]+)$#', $item['name'], $found); if ($result && count($found)) { $angle = rand(0, 314) / 100 - 1.57; $legend = $legendTemplate->cloneNode(true); $legend->removeAttribute('xml:id'); $legend->setAttribute('x', $e + $r * (1 + cos($angle))); $legend->setAttribute('y', $f + $r * (1 + sin($angle))); $legend->nodeValue = $found[1]; $legendTemplate->parentNode->appendChild($legend); } } $bad->parentNode->removeChild($bad); $good->parentNode->removeChild($good); $legendTemplate->parentNode->removeChild($legendTemplate); $temp = PHP_Depend_Util_FileUtil::getSysTempDir(); $temp .= '/' . uniqid('pdepend_') . '.svg'; $svg->save($temp); PHP_Depend_Util_ImageConvert::convert($temp, $this->logFile); // Remove temp file unlink($temp); }
/** * Tests that the convert util recognizes the imageConvert configuration * for the font-size: * * @return void */ public function testConvertRecognizesFontSizeInConfiguration() { $settings = new stdClass(); $settings->imageConvert = new stdClass(); $settings->imageConvert->fontSize = 14; $config = new PHP_Depend_Util_Configuration($settings); PHP_Depend_Util_ConfigurationInstance::set($config); $input = self::createInputSvg(); $output = self::createRunResourceURI('pdepend.svg'); PHP_Depend_Util_ImageConvert::convert($input, $output); $svg = file_get_contents($output); self::assertEquals(25, substr_count($svg, 'font-size:14px')); }
/** * Tests that the convert util recognizes the imageConvert configuration * for the font-size: * * @return void */ public function testConvertRecognizesFontSizeInConfiguration() { $config = new PHP_Depend_Util_Configuration('<?xml version="1.0"?> <configuration> <imageConvert> <fontSize>14</fontSize> </imageConvert> </configuration> '); PHP_Depend_Util_ConfigurationInstance::set($config); $this->_out = self::createRunResourceURI('pdepend.svg'); copy(dirname(__FILE__) . '/_input/pyramid.svg', $this->_out); $svg = file_get_contents($this->_out); preg_match_all('/font-size:\\s*11px/', $svg, $matches); $expected11 = count($matches[0]); preg_match_all('/font-size:\\s*14px/', $svg, $matches); $expected14 = count($matches[0]); $this->assertEquals(25, $expected11); $this->assertEquals(0, $expected14); PHP_Depend_Util_ImageConvert::convert($this->_out, $this->_out); $svg = file_get_contents($this->_out); preg_match_all('/font-size:\\s*11px/', $svg, $matches); $actual11 = count($matches[0]); preg_match_all('/font-size:\\s*14px/', $svg, $matches); $actual14 = count($matches[0]); $this->assertEquals(0, $actual11); $this->assertEquals(25, $actual14); }