Chris@13: name = $name; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Makes the property 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 property 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 property 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 property 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: * Sets default value for the property. Chris@0: * Chris@0: * @param mixed $value Default value to use Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function setDefault($value) { Chris@13: $this->default = BuilderHelpers::normalizeValue($value); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets doc comment for the property. Chris@0: * Chris@0: * @param PhpParser\Comment\Doc|string $docComment Doc comment to set Chris@0: * Chris@0: * @return $this The builder instance (for fluid interface) Chris@0: */ Chris@0: public function setDocComment($docComment) { Chris@13: $this->attributes = [ Chris@13: 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] Chris@13: ]; Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@17: * Sets the property type for PHP 7.4+. Chris@17: * Chris@17: * @param string|Name|NullableType|Identifier $type Chris@17: * Chris@17: * @return $this Chris@17: */ Chris@17: public function setType($type) { Chris@17: $this->type = BuilderHelpers::normalizeType($type); Chris@17: Chris@17: return $this; Chris@17: } Chris@17: Chris@17: /** Chris@0: * Returns the built class node. Chris@0: * Chris@0: * @return Stmt\Property The built property node Chris@0: */ Chris@13: public function getNode() : PhpParser\Node { Chris@0: return new Stmt\Property( Chris@0: $this->flags !== 0 ? $this->flags : Stmt\Class_::MODIFIER_PUBLIC, Chris@13: [ Chris@0: new Stmt\PropertyProperty($this->name, $this->default) Chris@13: ], Chris@17: $this->attributes, Chris@17: $this->type Chris@0: ); Chris@0: } Chris@13: }