1 | <?php |
||
7 | class Argument |
||
8 | { |
||
9 | /** |
||
10 | * An argument's name. |
||
11 | * |
||
12 | * Use this name when internally referring to the argument. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $name; |
||
17 | |||
18 | /** |
||
19 | * An argument's short representation. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $prefix; |
||
24 | |||
25 | /** |
||
26 | * An argument's long representation. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $longPrefix; |
||
31 | |||
32 | /** |
||
33 | * An argument's description. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $description; |
||
38 | |||
39 | /** |
||
40 | * Whether or not an argument is required. |
||
41 | * |
||
42 | * @var bool |
||
43 | */ |
||
44 | protected $required = false; |
||
45 | |||
46 | /** |
||
47 | * Whether or not an argument only needs to be defined to have a value. |
||
48 | * |
||
49 | * These arguments have the value true when they are defined on the command |
||
50 | * line. |
||
51 | * |
||
52 | * @var bool |
||
53 | */ |
||
54 | protected $noValue = false; |
||
55 | |||
56 | /** |
||
57 | * Which data type to cast an argument's value to. |
||
58 | * |
||
59 | * Valid data types are "string", "int", "float", and "bool". |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $castTo = 'string'; |
||
64 | |||
65 | /** |
||
66 | * An argument's default value. |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $defaultValue = []; |
||
71 | |||
72 | /** |
||
73 | * An argument's value, after type casting. |
||
74 | * |
||
75 | * @var string[]|int[]|float[]|bool[] |
||
76 | */ |
||
77 | protected $values = []; |
||
78 | |||
79 | /** |
||
80 | * Build a new command argument. |
||
81 | * |
||
82 | 48 | * @param string $name |
|
83 | */ |
||
84 | 48 | public function __construct($name) |
|
88 | |||
89 | /** |
||
90 | * Build a new command argument from an array. |
||
91 | * |
||
92 | * @param string $name |
||
93 | * @param array $params |
||
94 | * |
||
95 | 48 | * @return Argument |
|
96 | */ |
||
97 | 48 | public static function createFromArray($name, array $params) |
|
109 | 44 | ||
110 | /** |
||
111 | * Get argument params based on settable properties |
||
112 | * |
||
113 | * @param array $params |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | protected static function getSettableArgumentParams(array $params) |
||
131 | 48 | ||
132 | /** |
||
133 | * Retrieve an argument's name. |
||
134 | * |
||
135 | * Use this name when internally referring to the argument. |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | public function name() |
||
143 | 24 | ||
144 | /** |
||
145 | * Set an argument's name. |
||
146 | * |
||
147 | * Use this name when internally referring to the argument. |
||
148 | * |
||
149 | * @param string $name |
||
150 | */ |
||
151 | protected function setName($name) |
||
155 | 48 | ||
156 | 48 | /** |
|
157 | * Retrieve an argument's short form. |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | public function prefix() |
||
165 | 24 | ||
166 | /** |
||
167 | * Set an argument's short form. |
||
168 | * |
||
169 | * @param string $prefix |
||
170 | */ |
||
171 | protected function setPrefix($prefix) |
||
175 | 20 | ||
176 | 20 | /** |
|
177 | * Retrieve an argument's long form. |
||
178 | * |
||
179 | * @return string |
||
180 | */ |
||
181 | public function longPrefix() |
||
185 | 24 | ||
186 | /** |
||
187 | * Set an argument's short form. |
||
188 | * |
||
189 | * @param string $longPrefix |
||
190 | */ |
||
191 | protected function setLongPrefix($longPrefix) |
||
195 | 20 | ||
196 | 20 | /** |
|
197 | * Determine if an argument has a prefix. |
||
198 | * |
||
199 | * @return bool |
||
200 | */ |
||
201 | public function hasPrefix() |
||
205 | 20 | ||
206 | /** |
||
207 | * Retrieve an argument's description. |
||
208 | * |
||
209 | * @return string |
||
210 | */ |
||
211 | public function description() |
||
215 | 4 | ||
216 | /** |
||
217 | * Set an argument's description. |
||
218 | * |
||
219 | * @param string $description |
||
220 | */ |
||
221 | protected function setDescription($description) |
||
225 | 4 | ||
226 | 4 | /** |
|
227 | * Determine whether or not an argument is required. |
||
228 | * |
||
229 | * @return bool |
||
230 | */ |
||
231 | public function isRequired() |
||
235 | 20 | ||
236 | /** |
||
237 | * Set whether an argument is required or not. |
||
238 | * |
||
239 | * @param bool $required |
||
240 | */ |
||
241 | protected function setRequired($required) |
||
245 | 8 | ||
246 | 8 | /** |
|
247 | * Determine whether or not an argument only needs to be defined to have a |
||
248 | * value. |
||
249 | * |
||
250 | * @return bool |
||
251 | */ |
||
252 | public function noValue() |
||
256 | 40 | ||
257 | /** |
||
258 | * Set whether or not an argument only needs to be defined to have a value. |
||
259 | * |
||
260 | * @param bool $noValue |
||
261 | */ |
||
262 | protected function setNoValue($noValue) |
||
267 | 12 | ||
268 | 12 | /** |
|
269 | * Retrieve the data type to cast an argument's value to. |
||
270 | * |
||
271 | * @return string |
||
272 | */ |
||
273 | public function castTo() |
||
277 | 4 | ||
278 | /** |
||
279 | * Set the data type to cast an argument's value to. |
||
280 | * |
||
281 | * Valid data types are "string", "int", "float", and "bool". |
||
282 | * |
||
283 | * @throws \Exception if $castTo is not a valid data type. |
||
284 | * @param string $castTo |
||
285 | */ |
||
286 | protected function setCastTo($castTo) |
||
297 | 28 | ||
298 | 28 | /** |
|
299 | * Retrieve an argument's default values. |
||
300 | * |
||
301 | * @return string |
||
302 | */ |
||
303 | public function defaultValue() |
||
307 | 44 | ||
308 | /** |
||
309 | * Set an argument's default value. |
||
310 | * |
||
311 | * @param string $defaultValue |
||
312 | */ |
||
313 | public function setDefaultValue($defaultValue) |
||
320 | |||
321 | /** |
||
322 | * Retrieve an argument's value. |
||
323 | * |
||
324 | * Argument values are type cast based on the value of $castTo. |
||
325 | * |
||
326 | * @return string|int|float|bool |
||
327 | 28 | */ |
|
328 | public function value() |
||
336 | |||
337 | /** |
||
338 | * Retrieve an argument's values. |
||
339 | 36 | * |
|
340 | * Argument values are type cast based on the value of $castTo. |
||
341 | 36 | * |
|
342 | 36 | * @return string[]|int[]|float[]|bool[] |
|
343 | 36 | */ |
|
344 | public function values() |
||
352 | 24 | ||
353 | /** |
||
354 | * Set an argument's value based on its command line entry. |
||
355 | * |
||
356 | * Argument values are type cast based on the value of $castTo. |
||
357 | * |
||
358 | * @param string|bool $value |
||
359 | */ |
||
360 | 4 | public function setValue($value) |
|
365 | |||
366 | /** |
||
367 | * @param string $value |
||
368 | * |
||
369 | * @return string |
||
370 | 4 | */ |
|
371 | protected function castToString($value) |
||
375 | |||
376 | /** |
||
377 | * @param string $value |
||
378 | * |
||
379 | * @return int |
||
380 | 8 | */ |
|
381 | protected function castToInt($value) |
||
385 | |||
386 | /** |
||
387 | * @param string $value |
||
388 | * |
||
389 | * @return float |
||
390 | */ |
||
391 | protected function castToFloat($value) |
||
395 | |||
396 | /** |
||
397 | * @param string $value |
||
398 | * |
||
399 | * @return bool |
||
400 | */ |
||
401 | protected function castToBool($value) |
||
405 | } |
||
406 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..