mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-03-15 03:39:50 +01:00
Merge branch '3.x'
Conflicts: lib/PhpParser/Builder/Trait_.php test/PhpParser/Builder/TraitTest.php
This commit is contained in:
commit
efd39a67a2
@ -4,6 +4,7 @@ Version 3.1.1-dev
|
||||
### Fixed
|
||||
|
||||
* Fixed syntax error on comment after brace-style namespace declaration. (#412)
|
||||
* Added support for TraitUse statements in trait builder. (#413)
|
||||
|
||||
Version 3.1.0 (2017-07-28)
|
||||
--------------------------
|
||||
|
@ -9,6 +9,7 @@ use PhpParser\Node\Stmt;
|
||||
class Trait_ extends Declaration
|
||||
{
|
||||
protected $name;
|
||||
protected $uses = [];
|
||||
protected $properties = [];
|
||||
protected $methods = [];
|
||||
|
||||
@ -35,6 +36,8 @@ class Trait_ extends Declaration
|
||||
$this->properties[] = $stmt;
|
||||
} else if ($stmt instanceof Stmt\ClassMethod) {
|
||||
$this->methods[] = $stmt;
|
||||
} else if ($stmt instanceof Stmt\TraitUse) {
|
||||
$this->uses[] = $stmt;
|
||||
} else {
|
||||
throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
|
||||
}
|
||||
@ -50,7 +53,7 @@ class Trait_ extends Declaration
|
||||
public function getNode() : PhpParser\Node {
|
||||
return new Stmt\Trait_(
|
||||
$this->name, [
|
||||
'stmts' => array_merge($this->properties, $this->methods)
|
||||
'stmts' => array_merge($this->uses, $this->properties, $this->methods)
|
||||
], $this->attributes
|
||||
);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace PhpParser\Builder;
|
||||
|
||||
use PhpParser\Comment;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@ -19,14 +20,16 @@ class TraitTest extends TestCase
|
||||
$prop = new Stmt\Property(Stmt\Class_::MODIFIER_PUBLIC, [
|
||||
new Stmt\PropertyProperty('test')
|
||||
]);
|
||||
$use = new Stmt\TraitUse([new Name('OtherTrait')]);
|
||||
$trait = $this->createTraitBuilder('TestTrait')
|
||||
->setDocComment('/** Nice trait */')
|
||||
->addStmt($method1)
|
||||
->addStmts([$method2, $method3])
|
||||
->addStmt($prop)
|
||||
->addStmt($use)
|
||||
->getNode();
|
||||
$this->assertEquals(new Stmt\Trait_('TestTrait', [
|
||||
'stmts' => [$prop, $method1, $method2, $method3]
|
||||
'stmts' => [$use, $prop, $method1, $method2, $method3]
|
||||
], [
|
||||
'comments' => [
|
||||
new Comment\Doc('/** Nice trait */')
|
||||
|
Loading…
x
Reference in New Issue
Block a user