1 <?php declare(strict_types=1);
3 namespace PhpParser\Builder;
6 use PhpParser\BuilderHelpers;
8 use PhpParser\Node\Stmt;
10 class Function_ extends FunctionLike
13 protected $stmts = [];
16 * Creates a function builder.
18 * @param string $name Name of the function
20 public function __construct(string $name) {
27 * @param Node|PhpParser\Builder $stmt The statement to add
29 * @return $this The builder instance (for fluid interface)
31 public function addStmt($stmt) {
32 $this->stmts[] = BuilderHelpers::normalizeStmt($stmt);
38 * Returns the built function node.
40 * @return Stmt\Function_ The built function node
42 public function getNode() : Node {
43 return new Stmt\Function_($this->name, [
44 'byRef' => $this->returnByRef,
45 'params' => $this->params,
46 'returnType' => $this->returnType,
47 'stmts' => $this->stmts,
48 ], $this->attributes);