1 | <?php |
||
8 | trait ParamHelpers |
||
9 | { |
||
10 | protected function generateDummyValue(string $type) |
||
44 | |||
45 | /** |
||
46 | * Cast a value from a string to a specified type. |
||
47 | * |
||
48 | * @param string $value |
||
49 | * @param string $type |
||
50 | * |
||
51 | * @return mixed |
||
52 | */ |
||
53 | protected function castToType(string $value, string $type) |
||
77 | |||
78 | /** |
||
79 | * Normalizes the stated "type" of a parameter (eg "int", "integer", "double") |
||
80 | * to a number of standard types (integer, boolean, float). |
||
81 | * |
||
82 | * @param string $type |
||
83 | * |
||
84 | * @return mixed|string |
||
85 | */ |
||
86 | protected function normalizeParameterType(string $type) |
||
96 | |||
97 | /** |
||
98 | * Allows users to specify that we shouldn't generate an example for the parameter |
||
99 | * by writing 'No-example'. |
||
100 | * |
||
101 | * @param string $description |
||
102 | * |
||
103 | * @return bool If true, don't generate an example for this. |
||
104 | */ |
||
105 | protected function shouldExcludeExample(string $description) |
||
109 | |||
110 | /** |
||
111 | * Allows users to specify an example for the parameter by writing 'Example: the-example', |
||
112 | * to be used in example requests and response calls. |
||
113 | * |
||
114 | * @param string $description |
||
115 | * @param string $type The type of the parameter. Used to cast the example provided, if any. |
||
116 | * |
||
117 | * @return array The description and included example. |
||
118 | */ |
||
119 | protected function parseParamDescription(string $description, string $type) |
||
131 | } |
||
132 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: