1 | <?php |
||
18 | trait ParametersPart { |
||
19 | |||
20 | /** @var PhpParameter[] */ |
||
21 | private $parameters = []; |
||
22 | |||
23 | 44 | private function initParameters() { |
|
26 | |||
27 | /** |
||
28 | * Sets a collection of parameters |
||
29 | * |
||
30 | * Note: clears all parameters before setting the new ones |
||
31 | * |
||
32 | * @param PhpParameter[] $parameters |
||
33 | * @return $this |
||
34 | */ |
||
35 | 1 | public function setParameters(array $parameters) { |
|
43 | |||
44 | /** |
||
45 | * Adds a parameter |
||
46 | * |
||
47 | * @param PhpParameter $parameter |
||
48 | * @return $this |
||
49 | */ |
||
50 | 20 | public function addParameter(PhpParameter $parameter) { |
|
55 | |||
56 | /** |
||
57 | * Checks whether a parameter exists |
||
58 | * |
||
59 | * @param string $name parameter name |
||
60 | * @return bool `true` if a parameter exists and `false` if not |
||
61 | */ |
||
62 | 2 | public function hasParameter(string $name): bool { |
|
71 | |||
72 | /** |
||
73 | * A quick way to add a parameter which is created from the given parameters |
||
74 | * |
||
75 | * @param string $name |
||
76 | * @param string[]|PhpTypeInterface[] $types |
||
77 | * @param mixed $defaultValue omit the argument to define no default value |
||
78 | * |
||
79 | * @return $this |
||
80 | */ |
||
81 | 1 | public function addSimpleParameter(string $name, $types = null, $defaultValue = null) { |
|
93 | |||
94 | /** |
||
95 | * A quick way to add a parameter with description which is created from the given parameters |
||
96 | * |
||
97 | * @param string $name |
||
98 | * @param string[]|PhpTypeInterface[] $types |
||
99 | * @param null|string $typeDescription |
||
100 | * @param mixed $defaultValue omit the argument to define no default value |
||
101 | * |
||
102 | * @return $this |
||
103 | */ |
||
104 | 1 | public function addSimpleDescParameter(string $name, $types = null, string $typeDescription = null, $defaultValue = null) { |
|
117 | |||
118 | /** |
||
119 | * Returns a parameter by index or name |
||
120 | * |
||
121 | * @param string|int $nameOrIndex |
||
122 | * @throws \InvalidArgumentException |
||
123 | * @return PhpParameter |
||
124 | */ |
||
125 | 9 | public function getParameter($nameOrIndex): PhpParameter { |
|
139 | |||
140 | /** |
||
141 | * Replaces a parameter at a given position |
||
142 | * |
||
143 | * @param int $position |
||
144 | * @param PhpParameter $parameter |
||
145 | * @throws \InvalidArgumentException |
||
146 | * @return $this |
||
147 | */ |
||
148 | 2 | public function replaceParameter(int $position, PhpParameter $parameter) { |
|
154 | |||
155 | /** |
||
156 | * Remove a parameter at a given position |
||
157 | * |
||
158 | * @param int|string|PhpParameter $param |
||
159 | * @return $this |
||
160 | */ |
||
161 | 2 | public function removeParameter($param) { |
|
172 | |||
173 | 2 | private function removeParameterByPosition($position) { |
|
178 | |||
179 | 1 | private function removeParameterByName($name) { |
|
191 | |||
192 | 4 | private function checkPosition($position) { |
|
197 | |||
198 | /** |
||
199 | * Returns a collection of parameters |
||
200 | * |
||
201 | * @return PhpParameter[] |
||
202 | */ |
||
203 | 30 | public function getParameters() { |
|
206 | |||
207 | /** |
||
208 | * Returns the docblock |
||
209 | * |
||
210 | * @return Docblock |
||
211 | */ |
||
212 | abstract protected function getDocblock(): Docblock; |
||
213 | |||
214 | /** |
||
215 | * Generates docblock for params |
||
216 | */ |
||
217 | 12 | protected function generateParamDocblock(array $noTypeHint = []) { |
|
242 | |||
243 | } |
||
244 |