c029e748b74988b90f62754984a46f7cc4fb0681
[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     protected $variadic = false;
20
21     /**
22      * Creates a parameter builder.
23      *
24      * @param string $name Name of the parameter
25      */
26     public function __construct($name) {
27         $this->name = $name;
28     }
29
30     /**
31      * Sets default value for the parameter.
32      *
33      * @param mixed $value Default value to use
34      *
35      * @return $this The builder instance (for fluid interface)
36      */
37     public function setDefault($value) {
38         $this->default = $this->normalizeValue($value);
39
40         return $this;
41     }
42
43     /**
44      * Sets type hint for the parameter.
45      *
46      * @param string|Node\Name|Node\NullableType $type Type hint to use
47      *
48      * @return $this The builder instance (for fluid interface)
49      */
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');
54         }
55
56         return $this;
57     }
58
59     /**
60      * Make the parameter accept the value by reference.
61      *
62      * @return $this The builder instance (for fluid interface)
63      */
64     public function makeByRef() {
65         $this->byRef = true;
66
67         return $this;
68     }
69
70     /**
71      * Make the parameter variadic
72      *
73      * @return $this The builder instance (for fluid interface)
74      */
75     public function makeVariadic() {
76         $this->variadic = true;
77
78         return $this;
79     }
80
81     /**
82      * Returns the built parameter node.
83      *
84      * @return Node\Param The built parameter node
85      */
86     public function getNode() {
87         return new Node\Param(
88             $this->name, $this->default, $this->type, $this->byRef, $this->variadic
89         );
90     }
91 }