3e6e0f772e8c28a100127cd519446e577db7abe1
[yaffs-website] / vendor / nikic / php-parser / lib / PhpParser / Builder / Param.php
1 <?php
2
3 namespace PhpParser\Builder;
4
5 use PhpParser;
6 use PhpParser\Node;
7
8 class Param extends PhpParser\BuilderAbstract
9 {
10     protected $name;
11
12     protected $default = null;
13
14     /** @var string|Node\Name|Node\NullableType|null */
15     protected $type = null;
16
17     protected $byRef = false;
18
19     /**
20      * Creates a parameter builder.
21      *
22      * @param string $name Name of the parameter
23      */
24     public function __construct($name) {
25         $this->name = $name;
26     }
27
28     /**
29      * Sets default value for the parameter.
30      *
31      * @param mixed $value Default value to use
32      *
33      * @return $this The builder instance (for fluid interface)
34      */
35     public function setDefault($value) {
36         $this->default = $this->normalizeValue($value);
37
38         return $this;
39     }
40
41     /**
42      * Sets type hint for the parameter.
43      *
44      * @param string|Node\Name|Node\NullableType $type Type hint to use
45      *
46      * @return $this The builder instance (for fluid interface)
47      */
48     public function setTypeHint($type) {
49         $this->type = $this->normalizeType($type);
50         if ($this->type === 'void') {
51             throw new \LogicException('Parameter type cannot be void');
52         }
53
54         return $this;
55     }
56
57     /**
58      * Make the parameter accept the value by reference.
59      *
60      * @return $this The builder instance (for fluid interface)
61      */
62     public function makeByRef() {
63         $this->byRef = true;
64
65         return $this;
66     }
67
68     /**
69      * Returns the built parameter node.
70      *
71      * @return Node\Param The built parameter node
72      */
73     public function getNode() {
74         return new Node\Param(
75             $this->name, $this->default, $this->type, $this->byRef
76         );
77     }
78 }