Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ProcessDeleteNotification
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
1
 testProcessData
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsapi;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsdb\Notification as Query;
13use BO\Zmsdb\Config;
14use BO\Zmsdb\Process;
15use BO\Zmsdb\Department;
16
17/**
18  * @SuppressWarnings(Coupling)
19  */
20class ProcessDeleteNotification extends BaseController
21{
22    /**
23     * @SuppressWarnings(Param)
24     * @return String
25     */
26    public function readResponse(
27        \Psr\Http\Message\RequestInterface $request,
28        \Psr\Http\Message\ResponseInterface $response,
29        array $args
30    ) {
31        $input = Validator::input()->isJson()->assertValid()->getValue();
32        $process = new \BO\Zmsentities\Process($input);
33
34        $process->testValid();
35        $this->testProcessData($process);
36
37        \BO\Zmsdb\Connection\Select::getWriteConnection();
38
39        $config = (new Config())->readEntity();
40        $department = (new Department())->readByScopeId($process->scope->id);
41        $notification = (new \BO\Zmsentities\Notification())
42            ->toResolvedEntity($process, $config, $department, 'deleted');
43        $notification = (new Query())->writeInQueue($notification, \App::$now, false);
44        \App::$log->debug("Send notification", [$notification]);
45
46        $message = Response\Message::create($request);
47        $message->data = $notification;
48
49        $response = Render::withLastModified($response, time(), '0');
50        $response = Render::withJson($response, $message, 200);
51        return $response;
52    }
53
54    protected function testProcessData($process)
55    {
56        $authCheck = (new Process())->readAuthKeyByProcessId($process->id);
57        if (! $authCheck) {
58            throw new Exception\Process\ProcessNotFound();
59        } elseif (! $process->getFirstClient()->hasTelephone()) {
60            throw new Exception\Process\TelephoneRequired();
61        }
62    }
63}