3 namespace PhpParser\Builder;
6 use PhpParser\Node\Stmt;
8 class Trait_ extends Declaration
11 protected $uses = array();
12 protected $properties = array();
13 protected $methods = array();
16 * Creates an interface builder.
18 * @param string $name Name of the interface
20 public function __construct($name) {
27 * @param Stmt|PhpParser\Builder $stmt The statement to add
29 * @return $this The builder instance (for fluid interface)
31 public function addStmt($stmt) {
32 $stmt = $this->normalizeNode($stmt);
34 if ($stmt instanceof Stmt\Property) {
35 $this->properties[] = $stmt;
36 } else if ($stmt instanceof Stmt\ClassMethod) {
37 $this->methods[] = $stmt;
38 } else if ($stmt instanceof Stmt\TraitUse) {
39 $this->uses[] = $stmt;
41 throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
48 * Returns the built trait node.
50 * @return Stmt\Trait_ The built interface node
52 public function getNode() {
53 return new Stmt\Trait_(
55 'stmts' => array_merge($this->uses, $this->properties, $this->methods)