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