name = $name; $this->returnByRef = false; $this->params = array(); $this->stmts = array(); } /** * Make the function return by reference. * * @return self The builder instance (for fluid interface) */ public function makeReturnByRef() { $this->returnByRef = true; return $this; } /** * Adds a parameter. * * @param Node\Param|Param $param The parameter to add * * @return self The builder instance (for fluid interface) */ public function addParam($param) { $param = $this->normalizeNode($param); if (!$param instanceof Node\Param) { throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType())); } $this->params[] = $param; return $this; } /** * Adds multiple parameters. * * @param array $params The parameters to add * * @return self The builder instance (for fluid interface) */ public function addParams(array $params) { foreach ($params as $param) { $this->addParam($param); } return $this; } /** * Adds a statement. * * @param Node|PhpParser\Builder $stmt The statement to add * * @return self The builder instance (for fluid interface) */ public function addStmt($stmt) { $this->stmts[] = $this->normalizeNode($stmt); return $this; } /** * Adds multiple statements. * * @param array $stmts The statements to add * * @return self The builder instance (for fluid interface) */ public function addStmts(array $stmts) { foreach ($stmts as $stmt) { $this->addStmt($stmt); } return $this; } /** * Returns the built function node. * * @return Stmt\Function_ The built function node */ public function getNode() { return new Stmt\Function_($this->name, array( 'byRef' => $this->returnByRef, 'params' => $this->params, 'stmts' => $this->stmts, )); } }