| Conditions | 5 |
| Paths | 4 |
| Total Lines | 18 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | 15 | public function jsonFileToArray($filePath) |
|
| 20 | { |
||
| 21 | 15 | if (empty($filePath)) { |
|
| 22 | 1 | throw new \Exception('File path is empty'); |
|
| 23 | } |
||
| 24 | |||
| 25 | 14 | if (!file_exists($filePath) || !is_file($filePath)) { |
|
| 26 | 1 | throw new \Exception('File does not exist or is not a file'); |
|
| 27 | } |
||
| 28 | |||
| 29 | 13 | if (pathinfo($filePath, PATHINFO_EXTENSION) !== 'json') { |
|
| 30 | 1 | throw new \Exception('File is not a json file'); |
|
| 31 | } |
||
| 32 | |||
| 33 | 12 | $content = file_get_contents($filePath); |
|
| 34 | |||
| 35 | 12 | return (new StringUtility())->jsonToArray($content); |
|
| 36 | } |
||
| 37 | } |
||
| 38 |