1 | <?php |
||
10 | class InputModel |
||
11 | { |
||
12 | /** |
||
13 | * @var array form input (maps of strings, possibly nested) |
||
14 | */ |
||
15 | public $input; |
||
16 | |||
17 | /** |
||
18 | * @var string[] map where field name => error message |
||
19 | */ |
||
20 | protected $errors; |
||
21 | |||
22 | /** |
||
23 | * @var bool true, if any validation has been performed |
||
24 | */ |
||
25 | protected $validated = false; |
||
26 | |||
27 | /** |
||
28 | * @param array $input map where field name => input value(s) |
||
29 | * @param string[] $errors map where field name => error message |
||
30 | */ |
||
31 | 48 | public function __construct(array $input, array $errors) |
|
36 | |||
37 | /** |
||
38 | * @param InputModel|array|null $input map where field name => input value(s) |
||
39 | * @param string[] $errors map where field name => error message |
||
|
|||
40 | * |
||
41 | * @return self |
||
42 | */ |
||
43 | 48 | public static function create($input = null, $errors = null) |
|
51 | |||
52 | /** |
||
53 | * @param FieldInterface|string $field |
||
54 | * |
||
55 | * @return string|array|null value (or NULL, if no value exists in $input) |
||
56 | */ |
||
57 | 40 | public function getInput($field) |
|
73 | |||
74 | /** |
||
75 | * @param FieldInterface|string $field |
||
76 | * @param string|array|null $value |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | 15 | public function setInput($field, $value) |
|
94 | |||
95 | /** |
||
96 | * Get all accummulated error-messages, indexed by Field-name. |
||
97 | * |
||
98 | * @return string[] map where field-name => error message |
||
99 | */ |
||
100 | 3 | public function getErrors() |
|
104 | |||
105 | /** |
||
106 | * Get the error message for a given Field. |
||
107 | * |
||
108 | * @param FieldInterface|string $field |
||
109 | * |
||
110 | * @return string|string[]|null error-message (or NULL, if the given Field has no error) |
||
111 | */ |
||
112 | 19 | public function getError($field) |
|
116 | |||
117 | /** |
||
118 | * Set an error message for a given Field, if one is not already set for that |
||
119 | * Field - we only care about the first error message for each Field, so add |
||
120 | * error messages in order of importance. |
||
121 | * |
||
122 | * @param FieldInterface|string $field the field for which to set an error-message |
||
123 | * @param string $error error message |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | 24 | public function setError($field, $error) |
|
137 | |||
138 | /** |
||
139 | * @param FieldInterface|string $field |
||
140 | * |
||
141 | * @return bool true, if the given Field has an error message |
||
142 | * |
||
143 | * @see $errors |
||
144 | */ |
||
145 | 21 | public function hasError($field) |
|
149 | |||
150 | /** |
||
151 | * Clear the current error message for a given Field |
||
152 | * |
||
153 | * @param FieldInterface|string $field Field to clear error message for |
||
154 | * |
||
155 | * @return void |
||
156 | */ |
||
157 | 2 | public function clearError($field) |
|
161 | |||
162 | /** |
||
163 | * Check the model for errors - this does not take into account whether the |
||
164 | * form has been validated or not. |
||
165 | * |
||
166 | * @return bool true, if the form contains any error(s) |
||
167 | * |
||
168 | * @see isValid() |
||
169 | */ |
||
170 | 6 | public function hasErrors() |
|
174 | |||
175 | /** |
||
176 | * Check if the model has been validated and contains no errors. |
||
177 | * |
||
178 | * @return bool true, if the form has been validated and contains no errors. |
||
179 | * |
||
180 | * @see hasErrors() |
||
181 | */ |
||
182 | 3 | public function isValid() |
|
186 | |||
187 | /** |
||
188 | * Clears any accumulated error messages and marks the model as either |
||
189 | * non-validated (default) or validated. |
||
190 | * |
||
191 | * @param bool $validated true, if the model has been validated |
||
192 | * |
||
193 | * @return void |
||
194 | */ |
||
195 | 20 | public function clearErrors($validated = false) |
|
201 | } |
||
202 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.