Add support for global namespace in NS builder

NULL argument can now be used to create a global namespace {} block.
This commit is contained in:
Nikita Popov 2015-03-10 15:28:19 +01:00
parent a2d7e8977a
commit f9fc2fc9ee
2 changed files with 6 additions and 2 deletions

View File

@ -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;
}
/**

View File

@ -33,5 +33,9 @@ class NamespaceTest extends \PHPUnit_Framework_TestCase
->getNode()
;
$this->assertEquals($expected, $node);
$node = $this->createNamespaceBuilder(null)->getNode();
$this->assertNull($node->name);
$this->assertEmpty($node->stmts);
}
}