Skip to content

Commit f9fc2fc

Browse files
committed
Add support for global namespace in NS builder
NULL argument can now be used to create a global namespace {} block.
1 parent a2d7e89 commit f9fc2fc

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

lib/PhpParser/Builder/Namespace_.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class Namespace_ extends PhpParser\BuilderAbstract
1414
/**
1515
* Creates a namespace builder.
1616
*
17-
* @param Node\Name|string $name Name of the namespace
17+
* @param Node\Name|string|null $name Name of the namespace
1818
*/
1919
public function __construct($name) {
20-
$this->name = $this->normalizeName($name);
20+
$this->name = null !== $name ? $this->normalizeName($name) : null;
2121
}
2222

2323
/**

test/PhpParser/Builder/NamespaceTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ public function testCreation() {
3333
->getNode()
3434
;
3535
$this->assertEquals($expected, $node);
36+
37+
$node = $this->createNamespaceBuilder(null)->getNode();
38+
$this->assertNull($node->name);
39+
$this->assertEmpty($node->stmts);
3640
}
3741
}

0 commit comments

Comments
 (0)