| Total Complexity | 4 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 7 | class JsonHelper |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Converts value to JSON format |
||
| 11 | * @param mixed $value |
||
| 12 | * @return string |
||
| 13 | * @throws JsonException |
||
| 14 | */ |
||
| 15 | public static function encode($value): string |
||
| 16 | { |
||
| 17 | $result = json_encode($value); |
||
| 18 | if($error = json_last_error()) { |
||
| 19 | throw new JsonException(json_last_error_msg(), $error); |
||
| 20 | } |
||
| 21 | |||
| 22 | /** @var string $result */ |
||
| 23 | return $result; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Parses JSON to PHP value |
||
| 28 | * @param string $json |
||
| 29 | * @return mixed |
||
| 30 | * @throws JsonException |
||
| 31 | */ |
||
| 32 | public static function decode(string $json) |
||
| 40 | } |
||
| 41 | } |
||
| 42 |