1 <?php declare(strict_types=1);
3 namespace PhpParser\Builder;
6 use PhpParser\BuilderHelpers;
7 use PhpParser\Node\Stmt;
9 class Trait_ extends Declaration
13 protected $properties = [];
14 protected $methods = [];
17 * Creates an interface builder.
19 * @param string $name Name of the interface
21 public function __construct(string $name) {
28 * @param Stmt|PhpParser\Builder $stmt The statement to add
30 * @return $this The builder instance (for fluid interface)
32 public function addStmt($stmt) {
33 $stmt = BuilderHelpers::normalizeNode($stmt);
35 if ($stmt instanceof Stmt\Property) {
36 $this->properties[] = $stmt;
37 } elseif ($stmt instanceof Stmt\ClassMethod) {
38 $this->methods[] = $stmt;
39 } elseif ($stmt instanceof Stmt\TraitUse) {
40 $this->uses[] = $stmt;
42 throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
49 * Returns the built trait node.
51 * @return Stmt\Trait_ The built interface node
53 public function getNode() : PhpParser\Node {
54 return new Stmt\Trait_(
56 'stmts' => array_merge($this->uses, $this->properties, $this->methods)