Conditions | 6 |
Paths | 7 |
Total Lines | 29 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 42 |
Changes | 0 |
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(!$data->job || !$data->params) { |
||
24 | throw new Exception("Invalid rpc format"); |
||
25 | } |
||
26 | |||
27 | return [ |
||
28 | 'success' => true, |
||
29 | 'data' => $runner->dispatch($data->job, get_object_vars($data->params)), |
||
30 | ]; |
||
31 | |||
32 | } catch(Exception $e) { |
||
33 | |||
34 | return [ |
||
35 | 'success' => false, |
||
36 | 'message' => $e->getMessage() |
||
37 | ]; |
||
38 | } |
||
39 | } |
||
40 | } |
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: