| @@ 146-167 (lines=22) @@ | ||
| 143 | ||
| 144 | Assert::isArray($data); |
|
| 145 | ||
| 146 | foreach ($data as $field => &$value) { |
|
| 147 | switch ($field) { |
|
| 148 | case 'address': |
|
| 149 | Assert::stringNotEmpty($value); |
|
| 150 | ||
| 151 | break; |
|
| 152 | case 'vars': |
|
| 153 | if (is_array($value)) { |
|
| 154 | $value = json_encode($value); |
|
| 155 | } |
|
| 156 | // We should assert that "vars"'s $value is a string. |
|
| 157 | // no break |
|
| 158 | case 'name': |
|
| 159 | Assert::string($value); |
|
| 160 | ||
| 161 | break; |
|
| 162 | case 'subscribed': |
|
| 163 | Assert::oneOf($value, ['yes', 'no']); |
|
| 164 | ||
| 165 | break; |
|
| 166 | } |
|
| 167 | } |
|
| 168 | } |
|
| 169 | ||
| 170 | $params = [ |
|
| @@ 197-218 (lines=22) @@ | ||
| 194 | Assert::stringNotEmpty($address); |
|
| 195 | Assert::isArray($parameters); |
|
| 196 | ||
| 197 | foreach ($parameters as $field => &$value) { |
|
| 198 | switch ($field) { |
|
| 199 | case 'vars': |
|
| 200 | if (is_array($value)) { |
|
| 201 | $value = json_encode($value); |
|
| 202 | } |
|
| 203 | // We should assert that "vars"'s $value is a string. |
|
| 204 | // no break |
|
| 205 | case 'address': |
|
| 206 | Assert::stringNotEmpty($value); |
|
| 207 | ||
| 208 | break; |
|
| 209 | case 'name': |
|
| 210 | Assert::nullOrStringNotEmpty($value); |
|
| 211 | ||
| 212 | break; |
|
| 213 | case 'subscribed': |
|
| 214 | Assert::oneOf($value, ['yes', 'no']); |
|
| 215 | ||
| 216 | break; |
|
| 217 | } |
|
| 218 | } |
|
| 219 | ||
| 220 | if (array_key_exists('name', $parameters) && null === $parameters['name']) { |
|
| 221 | unset($parameters['name']); |
|