1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Add setDocComment() to namespace build (#437)

This commit is contained in:
Nikita Popov 2017-11-04 12:43:02 +01:00
parent 72231abe6d
commit 0ba710affa
3 changed files with 9 additions and 18 deletions

View File

@ -9,6 +9,7 @@ Version 3.1.2-dev
* Added `kind` attribute for `Stmt\Namespace_` node, which is one of `KIND_SEMICOLON` or * Added `kind` attribute for `Stmt\Namespace_` node, which is one of `KIND_SEMICOLON` or
`KIND_BRACED`. (#417) `KIND_BRACED`. (#417)
* Added `setDocComment()` method to namespace builder. (#437)
Version 3.1.1 (2017-09-02) Version 3.1.1 (2017-09-02)
-------------------------- --------------------------

View File

@ -6,7 +6,7 @@ use PhpParser;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
class Namespace_ extends PhpParser\BuilderAbstract class Namespace_ extends Declaration
{ {
private $name; private $name;
private $stmts = array(); private $stmts = array();
@ -33,27 +33,12 @@ class Namespace_ extends PhpParser\BuilderAbstract
return $this; 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. * Returns the built node.
* *
* @return Node The built node * @return Node The built node
*/ */
public function getNode() { public function getNode() {
return new Stmt\Namespace_($this->name, $this->stmts); return new Stmt\Namespace_($this->name, $this->stmts, $this->attributes);
} }
} }

View File

@ -2,6 +2,7 @@
namespace PhpParser\Builder; namespace PhpParser\Builder;
use PhpParser\Comment\Doc;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
@ -15,19 +16,23 @@ class NamespaceTest extends \PHPUnit_Framework_TestCase
$stmt1 = new Stmt\Class_('SomeClass'); $stmt1 = new Stmt\Class_('SomeClass');
$stmt2 = new Stmt\Interface_('SomeInterface'); $stmt2 = new Stmt\Interface_('SomeInterface');
$stmt3 = new Stmt\Function_('someFunction'); $stmt3 = new Stmt\Function_('someFunction');
$docComment = new Doc('/** Test */');
$expected = new Stmt\Namespace_( $expected = new Stmt\Namespace_(
new Node\Name('Name\Space'), new Node\Name('Name\Space'),
array($stmt1, $stmt2, $stmt3) array($stmt1, $stmt2, $stmt3),
array('comments' => array($docComment))
); );
$node = $this->createNamespaceBuilder('Name\Space') $node = $this->createNamespaceBuilder('Name\Space')
->addStmt($stmt1) ->addStmt($stmt1)
->addStmts(array($stmt2, $stmt3)) ->addStmts(array($stmt2, $stmt3))
->setDocComment($docComment)
->getNode() ->getNode()
; ;
$this->assertEquals($expected, $node); $this->assertEquals($expected, $node);
$node = $this->createNamespaceBuilder(new Node\Name(array('Name', 'Space'))) $node = $this->createNamespaceBuilder(new Node\Name(array('Name', 'Space')))
->setDocComment($docComment)
->addStmts(array($stmt1, $stmt2)) ->addStmts(array($stmt1, $stmt2))
->addStmt($stmt3) ->addStmt($stmt3)
->getNode() ->getNode()