PDepend\Report\Summary\Xml::close PHP Method

close() public method

Closes the logger process and writes the output file.
public close ( ) : void
return void
    public function close()
    {
        if ($this->logFile === null) {
            throw new NoLogOutputException($this);
        }
        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->formatOutput = true;
        $metrics = $dom->createElement('metrics');
        $metrics->setAttribute('generated', date('Y-m-d\\TH:i:s'));
        $metrics->setAttribute('pdepend', '@package_version@');
        foreach ($this->getProjectMetrics() as $name => $value) {
            $metrics->setAttribute($name, $value);
        }
        array_push($this->xmlStack, $metrics);
        foreach ($this->code as $node) {
            $node->accept($this);
        }
        if (count($this->fileSet) > 0) {
            $filesXml = $dom->createElement('files');
            foreach ($this->fileSet as $file) {
                $fileXml = $dom->createElement('file');
                $fileXml->setAttribute('name', Utf8Util::ensureEncoding($file->getFileName()));
                $this->writeNodeMetrics($fileXml, $file);
                $filesXml->appendChild($fileXml);
            }
            $metrics->insertBefore($filesXml, $metrics->firstChild);
        }
        $dom->appendChild($metrics);
        $buffer = $dom->saveXML();
        file_put_contents($this->logFile, $buffer);
    }

Usage Example

 /**
  * testNodeAwareAnalyzer
  *
  * @return void
  */
 public function testNodeAwareAnalyzer()
 {
     $this->namespaces = self::parseCodeResourceForTest();
     $input = array(array('loc' => 42), array('ncloc' => 23), array('loc' => 9), array('ncloc' => 7), array('loc' => 101), array('ncloc' => 99), array('loc' => 90), array('ncloc' => 80), array('loc' => 50), array('ncloc' => 45), array('loc' => 30), array('ncloc' => 22), array('loc' => 9), array('ncloc' => 9), array('loc' => 3), array('ncloc' => 3), array('loc' => 42), array('ncloc' => 23), array('loc' => 33), array('ncloc' => 20), array('loc' => 9), array('ncloc' => 7));
     $metricsOne = array();
     $metricsTwo = array();
     foreach ($this->namespaces as $namespace) {
         $metricsOne[$namespace->getId()] = array_shift($input);
         $metricsTwo[$namespace->getId()] = array_shift($input);
         foreach ($namespace->getClasses() as $class) {
             $metricsOne[$class->getId()] = array_shift($input);
             $metricsTwo[$class->getId()] = array_shift($input);
             foreach ($class->getMethods() as $method) {
                 $metricsOne[$method->getId()] = array_shift($input);
                 $metricsTwo[$method->getId()] = array_shift($input);
             }
         }
         foreach ($namespace->getFunctions() as $function) {
             $metricsOne[$function->getId()] = array_shift($input);
             $metricsTwo[$function->getId()] = array_shift($input);
         }
     }
     $resultOne = new AnalyzerNodeAwareDummy($metricsOne);
     $resultTwo = new AnalyzerNodeAwareDummy($metricsTwo);
     $log = new Xml();
     $log->setLogFile($this->resultFile);
     $log->setArtifacts($this->namespaces);
     $log->log($resultOne);
     $log->log($resultTwo);
     $log->close();
     $fileName = 'node-aware-result-set.xml';
     $this->assertXmlStringEqualsXmlString($this->getNormalizedPathXml(dirname(__FILE__) . "/_expected/{$fileName}"), $this->getNormalizedPathXml($this->resultFile));
 }