| Total Complexity | 6 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class JSON extends TextFile |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @param int<1, max> $depth |
||
| 9 | */ |
||
| 10 | public static function to_php(string $string, ?bool $assoc = false, int $depth = 512, int $options = 0) |
||
| 11 | { |
||
| 12 | // https://www.php.net/manual/en/function.json-decode.php |
||
| 13 | $ret = json_decode($string, $assoc, $depth, $options); |
||
| 14 | |||
| 15 | $error = self::hasErrors(); |
||
| 16 | if ($error !== false) { |
||
|
|
|||
| 17 | throw new \Exception("ParsingException: $error"); |
||
| 18 | } |
||
| 19 | |||
| 20 | return $ret; |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param int<1, max> $depth |
||
| 25 | */ |
||
| 26 | public static function from_php($var, $options = 0, $depth = 512): string |
||
| 37 | } |
||
| 38 | |||
| 39 | private static function hasErrors() : bool |
||
| 47 |