예제 #1
0
파일: Xml.php 프로젝트: pdepend/pdepend
 /**
  * Visits a namespace node.
  *
  * @param  \PDepend\Source\AST\ASTNamespace $namespace
  * @return void
  */
 public function visitNamespace(ASTNamespace $namespace)
 {
     $xml = end($this->xmlStack);
     $doc = $xml->ownerDocument;
     $packageXml = $doc->createElement('package');
     $packageXml->setAttribute('name', Utf8Util::ensureEncoding($namespace->getName()));
     array_push($this->xmlStack, $packageXml);
     foreach ($namespace->getTypes() as $type) {
         $type->accept($this);
     }
     foreach ($namespace->getFunctions() as $function) {
         $function->accept($this);
     }
     array_pop($this->xmlStack);
     if ($packageXml->firstChild === null) {
         return;
     }
     $xml->appendChild($packageXml);
 }
예제 #2
0
 /**
  * Returns an iterator with all generated {@link \PDepend\Source\AST\ASTNamespace}
  * objects.
  *
  * @return \PDepend\Source\AST\ASTArtifactList
  * @since  0.9.12
  */
 private function getPreparedNamespaces()
 {
     // Create a package array copy
     $namespaces = $this->namespaces;
     // Remove default package if empty
     if ($this->defaultPackage->getTypes()->count() === 0 && $this->defaultPackage->getFunctions()->count() === 0) {
         unset($namespaces[self::DEFAULT_NAMESPACE]);
     }
     return $namespaces;
 }
 /**
  * Tests that the {@link \PDepend\Source\AST\ASTNamespace::removeType()}
  * method unsets the package in the {@link \PDepend\Source\AST\ASTClass}
  * object and it tests the iterator to contain the new class.
  *
  * @return void
  */
 public function testRemoveType()
 {
     $namespace = new ASTNamespace('package1');
     $class2 = new ASTClass('Class2', 0, 'class2.php');
     $namespace->addType($class2);
     $namespace->removeType($class2);
     $this->assertEquals(0, $namespace->getTypes()->count());
 }