-<?php
+<?php declare(strict_types=1);
namespace PhpParser\Builder;
use PhpParser;
+use PhpParser\BuilderHelpers;
use PhpParser\Node\Stmt;
-class Property extends PhpParser\BuilderAbstract
+class Property implements PhpParser\Builder
{
protected $name;
protected $flags = 0;
protected $default = null;
- protected $attributes = array();
+ protected $attributes = [];
/**
* Creates a property builder.
*
* @param string $name Name of the property
*/
- public function __construct($name) {
+ public function __construct(string $name) {
$this->name = $name;
}
* @return $this The builder instance (for fluid interface)
*/
public function makePublic() {
- $this->setModifier(Stmt\Class_::MODIFIER_PUBLIC);
+ $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC);
return $this;
}
* @return $this The builder instance (for fluid interface)
*/
public function makeProtected() {
- $this->setModifier(Stmt\Class_::MODIFIER_PROTECTED);
+ $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED);
return $this;
}
* @return $this The builder instance (for fluid interface)
*/
public function makePrivate() {
- $this->setModifier(Stmt\Class_::MODIFIER_PRIVATE);
+ $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE);
return $this;
}
* @return $this The builder instance (for fluid interface)
*/
public function makeStatic() {
- $this->setModifier(Stmt\Class_::MODIFIER_STATIC);
+ $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC);
return $this;
}
* @return $this The builder instance (for fluid interface)
*/
public function setDefault($value) {
- $this->default = $this->normalizeValue($value);
+ $this->default = BuilderHelpers::normalizeValue($value);
return $this;
}
* @return $this The builder instance (for fluid interface)
*/
public function setDocComment($docComment) {
- $this->attributes = array(
- 'comments' => array($this->normalizeDocComment($docComment))
- );
+ $this->attributes = [
+ 'comments' => [BuilderHelpers::normalizeDocComment($docComment)]
+ ];
return $this;
}
*
* @return Stmt\Property The built property node
*/
- public function getNode() {
+ public function getNode() : PhpParser\Node {
return new Stmt\Property(
$this->flags !== 0 ? $this->flags : Stmt\Class_::MODIFIER_PUBLIC,
- array(
+ [
new Stmt\PropertyProperty($this->name, $this->default)
- ),
+ ],
$this->attributes
);
}
-}
\ No newline at end of file
+}