PDepend\Report\Jdepend\Xml::close PHP Метод

close() публичный Метод

Closes the logger process and writes the output file.
public close ( ) : void
Результат void
    public function close()
    {
        // Check for configured output
        if ($this->logFile === null) {
            throw new NoLogOutputException($this);
        }
        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->formatOutput = true;
        $jdepend = $dom->createElement('PDepend');
        $this->packages = $jdepend->appendChild($dom->createElement('Packages'));
        $this->cycles = $jdepend->appendChild($dom->createElement('Cycles'));
        foreach ($this->code as $node) {
            $node->accept($this);
        }
        $dom->appendChild($jdepend);
        $buffer = $dom->saveXML();
        file_put_contents($this->logFile, $buffer);
    }

Usage Example

 /**
  * Tests that {@link \PDepend\Report\Jdepend\Xml::write()} generates the
  * expected document structure for the source, but without any applied
  * metrics.
  *
  * @return void
  */
 public function testXmlLogWithoutMetrics()
 {
     $this->packages = self::parseCodeResourceForTest();
     $this->analyzer = new DependencyAnalyzer();
     $this->analyzer->analyze($this->packages);
     $log = new Xml();
     $log->setLogFile($this->resultFile);
     $log->setArtifacts($this->packages);
     $log->log($this->analyzer);
     $log->close();
     $fileName = 'pdepend-log' . CORE_PACKAGE . '.xml';
     $this->assertXmlStringEqualsXmlString($this->getNormalizedPathXml(dirname(__FILE__) . "/_expected/{$fileName}"), file_get_contents($this->resultFile));
 }