| 1 | <?php |
||
| 8 | class Param extends PhpParser\BuilderAbstract |
||
| 9 | { |
||
| 10 | protected $name; |
||
| 11 | |||
| 12 | protected $default = null; |
||
| 13 | protected $type = null; |
||
| 14 | protected $byRef = false; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Creates a parameter builder. |
||
| 18 | * |
||
| 19 | * @param string $name Name of the parameter |
||
| 20 | */ |
||
| 21 | public function __construct($name) { |
||
| 22 | $this->name = $name; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Sets default value for the parameter. |
||
| 27 | * |
||
| 28 | * @param mixed $value Default value to use |
||
| 29 | * |
||
| 30 | * @return $this The builder instance (for fluid interface) |
||
| 31 | */ |
||
| 32 | public function setDefault($value) { |
||
| 33 | $this->default = $this->normalizeValue($value); |
||
| 34 | |||
| 35 | return $this; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Sets type hint for the parameter. |
||
| 40 | * |
||
| 41 | * @param string|Node\Name $type Type hint to use |
||
| 42 | * |
||
| 43 | * @return $this The builder instance (for fluid interface) |
||
| 44 | */ |
||
| 45 | public function setTypeHint($type) { |
||
| 46 | if ($type === 'array' || $type === 'callable') { |
||
| 47 | $this->type = $type; |
||
| 48 | } else { |
||
| 49 | $this->type = $this->normalizeName($type); |
||
| 50 | } |
||
| 51 | |||
| 52 | return $this; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Make the parameter accept the value by reference. |
||
| 57 | * |
||
| 58 | * @return $this The builder instance (for fluid interface) |
||
| 59 | */ |
||
| 60 | public function makeByRef() { |
||
| 61 | $this->byRef = true; |
||
| 62 | |||
| 63 | return $this; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Returns the built parameter node. |
||
| 68 | * |
||
| 69 | * @return Node\Param The built parameter node |
||
| 70 | */ |
||
| 71 | public function getNode() { |
||
| 76 | } |