diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fdca50..cda6193 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Version 3.1.2-dev * Added `kind` attribute for `Stmt\Namespace_` node, which is one of `KIND_SEMICOLON` or `KIND_BRACED`. (#417) +* Added `setDocComment()` method to namespace builder. (#437) Version 3.1.1 (2017-09-02) -------------------------- diff --git a/lib/PhpParser/Builder/Namespace_.php b/lib/PhpParser/Builder/Namespace_.php index 432fcc7..fe636c4 100644 --- a/lib/PhpParser/Builder/Namespace_.php +++ b/lib/PhpParser/Builder/Namespace_.php @@ -6,7 +6,7 @@ use PhpParser; use PhpParser\Node; use PhpParser\Node\Stmt; -class Namespace_ extends PhpParser\BuilderAbstract +class Namespace_ extends Declaration { private $name; private $stmts = array(); @@ -33,27 +33,12 @@ class Namespace_ extends PhpParser\BuilderAbstract return $this; } - /** - * Adds multiple statements. - * - * @param array $stmts The statements to add - * - * @return $this The builder instance (for fluid interface) - */ - public function addStmts(array $stmts) { - foreach ($stmts as $stmt) { - $this->addStmt($stmt); - } - - return $this; - } - /** * Returns the built node. * * @return Node The built node */ public function getNode() { - return new Stmt\Namespace_($this->name, $this->stmts); + return new Stmt\Namespace_($this->name, $this->stmts, $this->attributes); } } diff --git a/test/PhpParser/Builder/NamespaceTest.php b/test/PhpParser/Builder/NamespaceTest.php index 54e8c93..88131fc 100644 --- a/test/PhpParser/Builder/NamespaceTest.php +++ b/test/PhpParser/Builder/NamespaceTest.php @@ -2,6 +2,7 @@ namespace PhpParser\Builder; +use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\Node\Stmt; @@ -15,19 +16,23 @@ class NamespaceTest extends \PHPUnit_Framework_TestCase $stmt1 = new Stmt\Class_('SomeClass'); $stmt2 = new Stmt\Interface_('SomeInterface'); $stmt3 = new Stmt\Function_('someFunction'); + $docComment = new Doc('/** Test */'); $expected = new Stmt\Namespace_( new Node\Name('Name\Space'), - array($stmt1, $stmt2, $stmt3) + array($stmt1, $stmt2, $stmt3), + array('comments' => array($docComment)) ); $node = $this->createNamespaceBuilder('Name\Space') ->addStmt($stmt1) ->addStmts(array($stmt2, $stmt3)) + ->setDocComment($docComment) ->getNode() ; $this->assertEquals($expected, $node); $node = $this->createNamespaceBuilder(new Node\Name(array('Name', 'Space'))) + ->setDocComment($docComment) ->addStmts(array($stmt1, $stmt2)) ->addStmt($stmt3) ->getNode()