| Total Complexity | 9 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | final class GetBlockTemplateValidator implements JsonValidator |
||
| 9 | { |
||
| 10 | /** @throws JsonFormatException */ |
||
| 11 | 8 | public static function validate(string $json): void |
|
| 12 | { |
||
| 13 | 8 | if (!$decoded = json_decode($json)) { |
|
| 14 | 1 | throw new JsonFormatException("JSON object has an invalid structure:\n$json"); |
|
| 15 | } |
||
| 16 | |||
| 17 | 7 | self::validateMode($decoded); |
|
| 18 | |||
| 19 | 6 | self::validateCapabilities($decoded); |
|
| 20 | 4 | } |
|
| 21 | |||
| 22 | /** @throws JsonFormatException */ |
||
| 23 | 7 | private static function validateMode(object $decoded): void |
|
| 24 | { |
||
| 25 | 7 | if (($decoded->mode ?? false) && ($decoded->mode !== 'template')) { |
|
| 26 | 1 | throw new JsonFormatException("JSON property `mode` must be either 'template' or omitted."); |
|
| 27 | } |
||
| 28 | 6 | } |
|
| 29 | |||
| 30 | /** @throws JsonFormatException */ |
||
| 31 | 6 | private static function validateCapabilities(object $decoded): void |
|
| 44 | } |
||
| 45 | 2 | }); |
|
| 46 | } |
||
| 49 |