3 namespace PhpParser\Builder;
6 use PhpParser\Node\Stmt;
8 class Property extends PhpParser\BuilderAbstract
13 protected $default = null;
14 protected $attributes = array();
17 * Creates a property builder.
19 * @param string $name Name of the property
21 public function __construct($name) {
26 * Makes the property public.
28 * @return $this The builder instance (for fluid interface)
30 public function makePublic() {
31 $this->setModifier(Stmt\Class_::MODIFIER_PUBLIC);
37 * Makes the property protected.
39 * @return $this The builder instance (for fluid interface)
41 public function makeProtected() {
42 $this->setModifier(Stmt\Class_::MODIFIER_PROTECTED);
48 * Makes the property private.
50 * @return $this The builder instance (for fluid interface)
52 public function makePrivate() {
53 $this->setModifier(Stmt\Class_::MODIFIER_PRIVATE);
59 * Makes the property static.
61 * @return $this The builder instance (for fluid interface)
63 public function makeStatic() {
64 $this->setModifier(Stmt\Class_::MODIFIER_STATIC);
70 * Sets default value for the property.
72 * @param mixed $value Default value to use
74 * @return $this The builder instance (for fluid interface)
76 public function setDefault($value) {
77 $this->default = $this->normalizeValue($value);
83 * Sets doc comment for the property.
85 * @param PhpParser\Comment\Doc|string $docComment Doc comment to set
87 * @return $this The builder instance (for fluid interface)
89 public function setDocComment($docComment) {
90 $this->attributes = array(
91 'comments' => array($this->normalizeDocComment($docComment))
98 * Returns the built class node.
100 * @return Stmt\Property The built property node
102 public function getNode() {
103 return new Stmt\Property(
104 $this->flags !== 0 ? $this->flags : Stmt\Class_::MODIFIER_PUBLIC,
106 new Stmt\PropertyProperty($this->name, $this->default)