Skip to content

Commit

Permalink
Add support for global namespace in NS builder
Browse files Browse the repository at this point in the history
NULL argument can now be used to create a global namespace {} block.
  • Loading branch information
nikic committed Mar 10, 2015
1 parent a2d7e89 commit f9fc2fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/PhpParser/Builder/Namespace_.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class Namespace_ extends PhpParser\BuilderAbstract
/**
* Creates a namespace builder.
*
* @param Node\Name|string $name Name of the namespace
* @param Node\Name|string|null $name Name of the namespace
*/
public function __construct($name) {
$this->name = $this->normalizeName($name);
$this->name = null !== $name ? $this->normalizeName($name) : null;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions test/PhpParser/Builder/NamespaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@ public function testCreation() {
->getNode()
;
$this->assertEquals($expected, $node);

$node = $this->createNamespaceBuilder(null)->getNode();
$this->assertNull($node->name);
$this->assertEmpty($node->stmts);
}
}

0 comments on commit f9fc2fc

Please sign in to comment.