Conditions | 5 |
Paths | 3 |
Total Lines | 16 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
25 | public static function loadJson(string $jsonFile): array |
||
26 | { |
||
27 | if (!file_exists($jsonFile) || !is_readable($jsonFile)) { |
||
28 | throw new IOException('JSON resource file not found or not readable.'); |
||
29 | } |
||
30 | |||
31 | $data = json_decode(file_get_contents($jsonFile) ?: '', true); |
||
32 | if ($data === null) { |
||
33 | $error = json_last_error(); |
||
34 | $msg = json_last_error_msg(); |
||
35 | throw new BadRulesException( |
||
36 | 'An error occured while parsing JSON file: error code #' . $error . ': ' . $msg |
||
37 | ); |
||
38 | } |
||
39 | |||
40 | return $data; |
||
41 | } |
||
43 |