| Conditions | 7 |
| Paths | 11 |
| Total Lines | 32 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 56 |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 11 | public function index(Runner $runner) |
||
|
|
|||
| 12 | { |
||
| 13 | try { |
||
| 14 | |||
| 15 | if(!array_key_exists('rpc', $_REQUEST)) { |
||
| 16 | throw new Exception("No rpc defined"); |
||
| 17 | } |
||
| 18 | $data = json_decode($_REQUEST['rpc']); |
||
| 19 | if(!$data) { |
||
| 20 | throw new Exception("Invalid rpc format"); |
||
| 21 | } |
||
| 22 | |||
| 23 | if(!property_exists($data, 'job') || !property_exists($data, 'params')) { |
||
| 24 | throw new Exception("Invalid rpc format"); |
||
| 25 | } |
||
| 26 | |||
| 27 | $params = is_object($data->params) ? get_object_vars($data->params) : []; |
||
| 28 | |||
| 29 | return [ |
||
| 30 | 'success' => true, |
||
| 31 | 'data' => $runner->dispatch($data->job, $params), |
||
| 32 | ]; |
||
| 33 | |||
| 34 | } catch(Exception $e) { |
||
| 35 | |||
| 36 | return [ |
||
| 37 | 'success' => false, |
||
| 38 | 'message' => $e->getMessage(), |
||
| 39 | 'trace' => explode(PHP_EOL, $e->getTraceAsString()), |
||
| 40 | ]; |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: