3 namespace PhpParser\Builder;
6 use PhpParser\Node\Name;
7 use PhpParser\Node\Stmt;
9 class Interface_ extends Declaration
12 protected $extends = array();
13 protected $constants = array();
14 protected $methods = array();
17 * Creates an interface builder.
19 * @param string $name Name of the interface
21 public function __construct($name) {
26 * Extends one or more interfaces.
28 * @param Name|string ...$interfaces Names of interfaces to extend
30 * @return $this The builder instance (for fluid interface)
32 public function extend() {
33 foreach (func_get_args() as $interface) {
34 $this->extends[] = $this->normalizeName($interface);
43 * @param Stmt|PhpParser\Builder $stmt The statement to add
45 * @return $this The builder instance (for fluid interface)
47 public function addStmt($stmt) {
48 $stmt = $this->normalizeNode($stmt);
50 $type = $stmt->getType();
52 case 'Stmt_ClassConst':
53 $this->constants[] = $stmt;
56 case 'Stmt_ClassMethod':
57 // we erase all statements in the body of an interface method
59 $this->methods[] = $stmt;
63 throw new \LogicException(sprintf('Unexpected node of type "%s"', $type));
70 * Returns the built interface node.
72 * @return Stmt\Interface_ The built interface node
74 public function getNode() {
75 return new Stmt\Interface_($this->name, array(
76 'extends' => $this->extends,
77 'stmts' => array_merge($this->constants, $this->methods),
78 ), $this->attributes);