/** * Creates a new, blank PHP source file. * * @param string|NULL $ns * If provided, the new document will have this namespace added to it. * * @return static */ public static function create($ns = NULL) { $node = new RootNode(); $node->addChild(Token::openTag()); if (is_string($ns) && $ns) { NamespaceNode::create($ns)->appendTo($node)->after(Token::newline()); } return $node; }
public function visitNamespaceNode(NamespaceNode $node) { $first = $node->getBody()->firstToken(); $has_braces = $first->getType() === '{'; $this->indentLevel = $has_braces ? 1 : 0; if (!$has_braces) { foreach ($node->children(Filter::isTokenType(';')) as $semicolon) { $next = $semicolon->next(); $newlines = str_repeat($this->config['nl'], 2); if ($next instanceof WhitespaceNode) { $next->setText($newlines); } else { $semicolon->after(Token::whitespace($newlines)); } } } }
public function testNamespaceNode() { $ns = NamespaceNode::create('\\Drupal\\pantaloons'); $this->assertInstanceOf('\\Pharborist\\Namespaces\\NamespaceNode', $ns); }
public function testCreate() { $namespace_node = NamespaceNode::create('\\Top\\Sub'); $this->assertEquals('\\Top\\Sub', $namespace_node->getName()->getAbsolutePath()); $this->assertNotNull($namespace_node->getBody()); }