-<?php
+<?php declare(strict_types=1);
namespace PhpParser\Builder;
use PhpParser;
+use PhpParser\BuilderHelpers;
use PhpParser\Node;
use PhpParser\Node\Stmt;
protected $flags = 0;
/** @var array|null */
- protected $stmts = array();
+ protected $stmts = [];
/**
* Creates a method builder.
*
* @param string $name Name of the method
*/
- 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;
}
throw new \LogicException('Cannot make method with statements abstract');
}
- $this->setModifier(Stmt\Class_::MODIFIER_ABSTRACT);
+ $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT);
$this->stmts = null; // abstract methods don't have statements
return $this;
* @return $this The builder instance (for fluid interface)
*/
public function makeFinal() {
- $this->setModifier(Stmt\Class_::MODIFIER_FINAL);
+ $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL);
return $this;
}
throw new \LogicException('Cannot add statements to an abstract method');
}
- $this->stmts[] = $this->normalizeNode($stmt);
+ $this->stmts[] = BuilderHelpers::normalizeStmt($stmt);
return $this;
}
*
* @return Stmt\ClassMethod The built method node
*/
- public function getNode() {
- return new Stmt\ClassMethod($this->name, array(
+ public function getNode() : Node {
+ return new Stmt\ClassMethod($this->name, [
'flags' => $this->flags,
'byRef' => $this->returnByRef,
'params' => $this->params,
'returnType' => $this->returnType,
'stmts' => $this->stmts,
- ), $this->attributes);
+ ], $this->attributes);
}
}