Kill the BuilderAbstract::$flags property

Instead pass and return the flags explicitly.
This commit is contained in:
Nikita Popov 2017-04-24 21:06:54 +02:00
parent 9dc93aafaa
commit 6b6c903585
4 changed files with 20 additions and 19 deletions

View File

@ -62,7 +62,7 @@ class Class_ extends Declaration
* @return $this The builder instance (for fluid interface)
*/
public function makeAbstract() {
$this->setModifier(Stmt\Class_::MODIFIER_ABSTRACT);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT);
return $this;
}
@ -73,7 +73,7 @@ class Class_ extends Declaration
* @return $this The builder instance (for fluid interface)
*/
public function makeFinal() {
$this->setModifier(Stmt\Class_::MODIFIER_FINAL);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL);
return $this;
}

View File

@ -29,7 +29,7 @@ class Method extends FunctionLike
* @return $this The builder instance (for fluid interface)
*/
public function makePublic() {
$this->setModifier(Stmt\Class_::MODIFIER_PUBLIC);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC);
return $this;
}
@ -40,7 +40,7 @@ class Method extends FunctionLike
* @return $this The builder instance (for fluid interface)
*/
public function makeProtected() {
$this->setModifier(Stmt\Class_::MODIFIER_PROTECTED);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED);
return $this;
}
@ -51,7 +51,7 @@ class Method extends FunctionLike
* @return $this The builder instance (for fluid interface)
*/
public function makePrivate() {
$this->setModifier(Stmt\Class_::MODIFIER_PRIVATE);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE);
return $this;
}
@ -62,7 +62,7 @@ class Method extends FunctionLike
* @return $this The builder instance (for fluid interface)
*/
public function makeStatic() {
$this->setModifier(Stmt\Class_::MODIFIER_STATIC);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC);
return $this;
}
@ -77,7 +77,7 @@ class Method extends FunctionLike
throw new \LogicException('Cannot make method with statements abstract');
}
$this->setModifier(Stmt\Class_::MODIFIER_ABSTRACT);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT);
$this->stmts = null; // abstract methods don't have statements
return $this;
@ -89,7 +89,7 @@ class Method extends FunctionLike
* @return $this The builder instance (for fluid interface)
*/
public function makeFinal() {
$this->setModifier(Stmt\Class_::MODIFIER_FINAL);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL);
return $this;
}

View File

@ -28,7 +28,7 @@ class Property extends PhpParser\BuilderAbstract
* @return $this The builder instance (for fluid interface)
*/
public function makePublic() {
$this->setModifier(Stmt\Class_::MODIFIER_PUBLIC);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC);
return $this;
}
@ -39,7 +39,7 @@ class Property extends PhpParser\BuilderAbstract
* @return $this The builder instance (for fluid interface)
*/
public function makeProtected() {
$this->setModifier(Stmt\Class_::MODIFIER_PROTECTED);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED);
return $this;
}
@ -50,7 +50,7 @@ class Property extends PhpParser\BuilderAbstract
* @return $this The builder instance (for fluid interface)
*/
public function makePrivate() {
$this->setModifier(Stmt\Class_::MODIFIER_PRIVATE);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE);
return $this;
}
@ -61,7 +61,7 @@ class Property extends PhpParser\BuilderAbstract
* @return $this The builder instance (for fluid interface)
*/
public function makeStatic() {
$this->setModifier(Stmt\Class_::MODIFIER_STATIC);
$this->flags = $this->addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC);
return $this;
}

View File

@ -10,8 +10,6 @@ use PhpParser\Node\Scalar;
use PhpParser\Node\Stmt;
abstract class BuilderAbstract implements Builder {
protected $flags;
/**
* Normalizes a node: Converts builder objects to nodes.
*
@ -188,12 +186,15 @@ abstract class BuilderAbstract implements Builder {
}
/**
* Sets a modifier in the $this->type property.
* Adds a modifier and returns new modifier bitmask.
*
* @param int $modifier Modifier to set
* @param int $modifiers Existing modifiers
* @param int $modifier Modifier to set
*
* @return int New modifiers
*/
protected function setModifier($modifier) {
Stmt\Class_::verifyModifier($this->flags, $modifier);
$this->flags |= $modifier;
protected function addModifier($modifiers, $modifier) {
Stmt\Class_::verifyModifier($modifiers, $modifier);
return $modifiers | $modifier;
}
}