| Conditions | 4 |
| Paths | 5 |
| Total Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function parse() |
||
| 23 | { |
||
| 24 | $path = $this->getPath(); |
||
| 25 | // Require the file, if it throws an exception, rethrow it |
||
| 26 | try { |
||
| 27 | /** @noinspection PhpIncludeInspection */ |
||
| 28 | $temp = require $path; |
||
| 29 | } catch (Exception $exception) { |
||
| 30 | throw new ParseException( |
||
| 31 | [ |
||
| 32 | 'message' => 'PHP file threw an exception', |
||
| 33 | 'exception' => $exception, |
||
| 34 | ] |
||
| 35 | ); |
||
| 36 | } |
||
| 37 | |||
| 38 | // If we have a callable, run it and expect an array back |
||
| 39 | if (is_callable($temp)) { |
||
| 40 | $temp = call_user_func($temp); |
||
| 41 | } |
||
| 42 | |||
| 43 | // Check for array, if its anything else, throw an exception |
||
| 44 | if (!is_array($temp)) { |
||
| 45 | throw new UnsupportedFormatException('PHP file does not return an array'); |
||
| 46 | } |
||
| 47 | |||
| 48 | return $temp; |
||
| 49 | } |
||
| 50 | |||
| 59 |