Mercurial > hg > cmmr2012-drupal-site
comparison vendor/nikic/php-parser/lib/PhpParser/Builder/Param.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php declare(strict_types=1); | |
2 | |
3 namespace PhpParser\Builder; | |
4 | |
5 use PhpParser; | |
6 use PhpParser\BuilderHelpers; | |
7 use PhpParser\Node; | |
8 | |
9 class Param implements PhpParser\Builder | |
10 { | |
11 protected $name; | |
12 | |
13 protected $default = null; | |
14 | |
15 /** @var string|Node\Name|Node\NullableType|null */ | |
16 protected $type = null; | |
17 | |
18 protected $byRef = false; | |
19 | |
20 protected $variadic = false; | |
21 | |
22 /** | |
23 * Creates a parameter builder. | |
24 * | |
25 * @param string $name Name of the parameter | |
26 */ | |
27 public function __construct(string $name) { | |
28 $this->name = $name; | |
29 } | |
30 | |
31 /** | |
32 * Sets default value for the parameter. | |
33 * | |
34 * @param mixed $value Default value to use | |
35 * | |
36 * @return $this The builder instance (for fluid interface) | |
37 */ | |
38 public function setDefault($value) { | |
39 $this->default = BuilderHelpers::normalizeValue($value); | |
40 | |
41 return $this; | |
42 } | |
43 | |
44 /** | |
45 * Sets type hint for the parameter. | |
46 * | |
47 * @param string|Node\Name|Node\NullableType $type Type hint to use | |
48 * | |
49 * @return $this The builder instance (for fluid interface) | |
50 */ | |
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'); | |
55 } | |
56 | |
57 return $this; | |
58 } | |
59 | |
60 /** | |
61 * Make the parameter accept the value by reference. | |
62 * | |
63 * @return $this The builder instance (for fluid interface) | |
64 */ | |
65 public function makeByRef() { | |
66 $this->byRef = true; | |
67 | |
68 return $this; | |
69 } | |
70 | |
71 /** | |
72 * Make the parameter variadic | |
73 * | |
74 * @return $this The builder instance (for fluid interface) | |
75 */ | |
76 public function makeVariadic() { | |
77 $this->variadic = true; | |
78 | |
79 return $this; | |
80 } | |
81 | |
82 /** | |
83 * Returns the built parameter node. | |
84 * | |
85 * @return Node\Param The built parameter node | |
86 */ | |
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 | |
91 ); | |
92 } | |
93 } |