PDepend\Report\Overview\Pyramid::close PHP Method

close() public method

Closes the logger process and writes the output file.
public close ( ) : void
return void
    public function close()
    {
        // Check for configured log file
        if ($this->logFile === null) {
            throw new NoLogOutputException($this);
        }
        $metrics = $this->collectMetrics();
        $proportions = $this->computeProportions($metrics);
        $svg = new \DOMDocument('1.0', 'UTF-8');
        $svg->loadXML(file_get_contents(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 = FileUtil::getSysTempDir();
        $temp .= '/' . uniqid('pdepend_') . '.svg';
        $svg->save($temp);
        ImageConvert::convert($temp, $this->logFile);
        // Remove temp file
        unlink($temp);
    }

Usage Example

 /**
  * testCollectedAndComputedValuesInOutputSVG
  *
  * @return void
  */
 public function testCollectedAndComputedValuesInOutputSVG()
 {
     $output = self::createRunResourceURI('temp.svg');
     if (file_exists($output)) {
         unlink($output);
     }
     $log = new Pyramid();
     $log->setLogFile($output);
     $log->log($this->createCouplingAnalyzer());
     $log->log($this->createComplexityAnalyzer());
     $log->log($this->createInheritanceAnalyzer());
     $log->log($this->createNodeCountAnalyzer());
     $log->log($this->createNodeLocAnalyzer());
     $log->close();
     $this->assertFileExists($output);
     $expected = array('cyclo' => 5579, 'loc' => 35175, 'nom' => 3618, 'noc' => 384, 'nop' => 19, 'andc' => 0.31, 'ahh' => 0.12, 'calls' => 15128, 'fanout' => 8590, 'cyclo-loc' => 0.15, 'loc-nom' => 9.720000000000001, 'nom-noc' => 9.42, 'noc-nop' => 20.21, 'fanout-calls' => 0.5600000000000001, 'calls-nom' => 4.18);
     $svg = new \DOMDocument();
     $svg->load($output);
     // TODO: Replace this loop assertion
     foreach ($expected as $name => $value) {
         $elem = $svg->getElementById("pdepend.{$name}");
         $this->assertInstanceOf('\\DOMElement', $elem);
         $this->assertEquals($value, $elem->nodeValue, null, 0.01);
     }
     unlink($output);
 }