| Conditions | 7 |
| Paths | 5 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | public static function validate(string $json) |
||
| 12 | { |
||
| 13 | if (!$decoded = json_decode($json)) { |
||
| 14 | throw new JsonFormatException("JSON object has an invalid structure:\n$json"); |
||
| 15 | } |
||
| 16 | |||
| 17 | if (($decoded->mode ?? false) && ($decoded->mode !== 'template')) { |
||
| 18 | throw new JsonFormatException("JSON property `mode` must be either 'template' or omitted."); |
||
| 19 | } |
||
| 20 | |||
| 21 | if ($decoded->capabilities ?? false) { |
||
| 22 | if (!is_array($decoded->capabilities)) { |
||
| 23 | throw new JsonFormatException( |
||
| 24 | 'JSON property `capabilities` must be of type `array`, `' . |
||
| 25 | gettype($decoded->capabilities) . '` provided.' |
||
| 26 | ); |
||
| 27 | } |
||
| 28 | |||
| 29 | array_walk($decoded->capabilities, function ($item) { |
||
| 30 | if (!is_string($item)) { |
||
| 31 | throw new JsonFormatException("JSON property `capabilities` must only contain strings."); |
||
| 32 | } |
||
| 37 |