1 <?php declare(strict_types=1);
3 namespace PhpParser\Builder;
6 use PhpParser\BuilderHelpers;
9 class Param implements PhpParser\Builder
13 protected $default = null;
15 /** @var string|Node\Name|Node\NullableType|null */
16 protected $type = null;
18 protected $byRef = false;
20 protected $variadic = false;
23 * Creates a parameter builder.
25 * @param string $name Name of the parameter
27 public function __construct(string $name) {
32 * Sets default value for the parameter.
34 * @param mixed $value Default value to use
36 * @return $this The builder instance (for fluid interface)
38 public function setDefault($value) {
39 $this->default = BuilderHelpers::normalizeValue($value);
45 * Sets type hint for the parameter.
47 * @param string|Node\Name|Node\NullableType $type Type hint to use
49 * @return $this The builder instance (for fluid interface)
51 public function setTypeHint($type) {
52 $this->type = BuilderHelpers::normalizeType($type);
53 if ($this->type == 'void') {
54 throw new \LogicException('Parameter type cannot be void');
61 * Make the parameter accept the value by reference.
63 * @return $this The builder instance (for fluid interface)
65 public function makeByRef() {
72 * Make the parameter variadic
74 * @return $this The builder instance (for fluid interface)
76 public function makeVariadic() {
77 $this->variadic = true;
83 * Returns the built parameter node.
85 * @return Node\Param The built parameter node
87 public function getNode() : Node {
88 return new Node\Param(
89 new Node\Expr\Variable($this->name),
90 $this->default, $this->type, $this->byRef, $this->variadic