| Conditions | 9 |
| Paths | 12 |
| Total Lines | 29 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 90 |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 21 | { |
||
| 22 | $body = $request->getParsedBody(); |
||
| 23 | |||
| 24 | if (!isset($body['profile']) or !$profile = new Profile($body['profile'])) { |
||
| 25 | throw new \RuntimeException('Missing profile'); |
||
| 26 | } |
||
| 27 | |||
| 28 | if (!isset($body['job']) or !$job = new $body['job']) { |
||
| 29 | throw new \RuntimeException('Missing job'); |
||
| 30 | } |
||
| 31 | |||
| 32 | $parameters = isset($body['parameters']) ? $body['parameters'] : []; |
||
| 33 | if (!is_array($parameters)) { |
||
| 34 | throw new \RuntimeException('Malformed parameters'); |
||
| 35 | } |
||
| 36 | |||
| 37 | $tags = isset($body['tags']) ? $body['tags'] : []; |
||
| 38 | if (!is_array($tags)) { |
||
| 39 | throw new \RuntimeException('Malformed tags'); |
||
| 40 | } |
||
| 41 | |||
| 42 | $task = new Task($profile, $job, $parameters, $tags); |
||
| 43 | |||
| 44 | ServiceContainer::getInstance() |
||
| 45 | ->queue |
||
| 46 | ->add($task); |
||
| 47 | |||
| 48 | return new JsonResponse($task); |
||
| 49 | } |
||
| 51 |