| Conditions | 5 |
| Paths | 5 |
| Total Lines | 26 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 5 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | 12 | public function parse($path) |
|
| 29 | { |
||
| 30 | // Require the file, if it throws an exception, rethrow it |
||
| 31 | try { |
||
| 32 | 12 | $temp = require $path; |
|
| 33 | 9 | } catch (Exception $ex) { |
|
| 34 | 3 | throw new ParseException( |
|
| 35 | [ |
||
| 36 | 3 | 'message' => 'PHP file threw an exception', |
|
| 37 | 3 | 'exception' => $ex, |
|
| 38 | ] |
||
| 39 | 2 | ); |
|
| 40 | } |
||
| 41 | |||
| 42 | // If we have a callable, run it and expect an array back |
||
| 43 | 9 | if (is_callable($temp)) { |
|
| 44 | 3 | $temp = call_user_func($temp); |
|
| 45 | 2 | } |
|
| 46 | |||
| 47 | // Check for array, if its anything else, throw an exception |
||
| 48 | 9 | if (empty($temp) || !is_array($temp)) { |
|
| 49 | 3 | throw new UnsupportedFileFormatException('PHP file does not return an array'); |
|
| 50 | } |
||
| 51 | |||
| 52 | 6 | return $temp; |
|
| 53 | } |
||
| 54 | |||
| 66 |