Conditions | 5 |
Paths | 4 |
Total Lines | 18 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
17 | public function create($json) |
||
18 | { |
||
19 | $taskArray = json_decode($json, true); |
||
20 | |||
21 | if (json_last_error() !== JSON_ERROR_NONE) { |
||
22 | throw new InvalidJSONTaskException("String is not valid JSON"); |
||
23 | } |
||
24 | |||
25 | if (!isset($taskArray['name'], $taskArray['body'])) { |
||
26 | throw new InvalidJSONTaskException("Cannot reconstruct task. Name or body fields are missing"); |
||
27 | } |
||
28 | |||
29 | try { |
||
30 | return new Task($taskArray['name'], $taskArray['body'], isset($taskArray['delay']) ? $taskArray['delay'] : 0); |
||
31 | } catch (TaskException $e) { |
||
32 | throw new InvalidJSONTaskException("Failed creating Task instance", 0, $e); |
||
33 | } |
||
34 | } |
||
35 | } |
||
36 |