Chris@13: name = $name; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Makes the method public. Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function makePublic() { Chris@13: $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Makes the method protected. Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function makeProtected() { Chris@13: $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Makes the method private. Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function makePrivate() { Chris@13: $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Makes the method static. Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function makeStatic() { Chris@13: $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Makes the method abstract. Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function makeAbstract() { Chris@0: if (!empty($this->stmts)) { Chris@0: throw new \LogicException('Cannot make method with statements abstract'); Chris@0: } Chris@0: Chris@13: $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT); Chris@0: $this->stmts = null; // abstract methods don't have statements Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Makes the method final. Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function makeFinal() { Chris@13: $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a statement. Chris@0: * Chris@0: * @param Node|PhpParser\Builder $stmt The statement to add Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function addStmt($stmt) { Chris@0: if (null === $this->stmts) { Chris@0: throw new \LogicException('Cannot add statements to an abstract method'); Chris@0: } Chris@0: Chris@13: $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the built method node. Chris@0: * Chris@0: * @return Stmt\ClassMethod The built method node Chris@0: */ Chris@13: public function getNode() : Node { Chris@13: return new Stmt\ClassMethod($this->name, [ Chris@0: 'flags' => $this->flags, Chris@0: 'byRef' => $this->returnByRef, Chris@0: 'params' => $this->params, Chris@0: 'returnType' => $this->returnType, Chris@0: 'stmts' => $this->stmts, Chris@13: ], $this->attributes); Chris@0: } Chris@0: }