/** * 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); }
/** * 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::removeFunction()} * method unsets the actual package as {@link \PDepend\Source\AST\ASTFunction} * owner. * * @return void */ public function testRemoveFunction() { $namespace = new ASTNamespace('package1'); $function1 = new ASTFunction('func1', 0); $function2 = new ASTFunction('func2', 0); $namespace->addFunction($function1); $namespace->addFunction($function2); $namespace->removeFunction($function2); $this->assertEquals(1, $namespace->getFunctions()->count()); }