1 <?php declare(strict_types=1);
3 namespace PhpParser\Builder;
6 use PhpParser\BuilderHelpers;
7 use PhpParser\Node\Stmt;
9 class Property implements PhpParser\Builder
14 protected $default = null;
15 protected $attributes = [];
18 * Creates a property builder.
20 * @param string $name Name of the property
22 public function __construct(string $name) {
27 * Makes the property public.
29 * @return $this The builder instance (for fluid interface)
31 public function makePublic() {
32 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC);
38 * Makes the property protected.
40 * @return $this The builder instance (for fluid interface)
42 public function makeProtected() {
43 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED);
49 * Makes the property private.
51 * @return $this The builder instance (for fluid interface)
53 public function makePrivate() {
54 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE);
60 * Makes the property static.
62 * @return $this The builder instance (for fluid interface)
64 public function makeStatic() {
65 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC);
71 * Sets default value for the property.
73 * @param mixed $value Default value to use
75 * @return $this The builder instance (for fluid interface)
77 public function setDefault($value) {
78 $this->default = BuilderHelpers::normalizeValue($value);
84 * Sets doc comment for the property.
86 * @param PhpParser\Comment\Doc|string $docComment Doc comment to set
88 * @return $this The builder instance (for fluid interface)
90 public function setDocComment($docComment) {
92 'comments' => [BuilderHelpers::normalizeDocComment($docComment)]
99 * Returns the built class node.
101 * @return Stmt\Property The built property node
103 public function getNode() : PhpParser\Node {
104 return new Stmt\Property(
105 $this->flags !== 0 ? $this->flags : Stmt\Class_::MODIFIER_PUBLIC,
107 new Stmt\PropertyProperty($this->name, $this->default)