3 namespace PhpParser\Builder;
8 class Param extends PhpParser\BuilderAbstract
12 protected $default = null;
14 /** @var string|Node\Name|Node\NullableType|null */
15 protected $type = null;
17 protected $byRef = false;
19 protected $variadic = false;
22 * Creates a parameter builder.
24 * @param string $name Name of the parameter
26 public function __construct($name) {
31 * Sets default value for the parameter.
33 * @param mixed $value Default value to use
35 * @return $this The builder instance (for fluid interface)
37 public function setDefault($value) {
38 $this->default = $this->normalizeValue($value);
44 * Sets type hint for the parameter.
46 * @param string|Node\Name|Node\NullableType $type Type hint to use
48 * @return $this The builder instance (for fluid interface)
50 public function setTypeHint($type) {
51 $this->type = $this->normalizeType($type);
52 if ($this->type === 'void') {
53 throw new \LogicException('Parameter type cannot be void');
60 * Make the parameter accept the value by reference.
62 * @return $this The builder instance (for fluid interface)
64 public function makeByRef() {
71 * Make the parameter variadic
73 * @return $this The builder instance (for fluid interface)
75 public function makeVariadic() {
76 $this->variadic = true;
82 * Returns the built parameter node.
84 * @return Node\Param The built parameter node
86 public function getNode() {
87 return new Node\Param(
88 $this->name, $this->default, $this->type, $this->byRef, $this->variadic