Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ProcessDeleteNotification
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
18 / 18
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        $process->testValid();
34        $this->testProcessData($process);
35        $process = (new Process())->readEntity($process->id, $process->authKey);
36        $process->addData($input);
37
38        \BO\Zmsdb\Connection\Select::getWriteConnection();
39
40        $config = (new Config())->readEntity();
41        $department = (new Department())->readByScopeId($process->scope['id']);
42        $notification = (new \BO\Zmsentities\Notification())
43            ->toResolvedEntity($process, $config, $department, 'deleted');
44        $notification = (new Query())->writeInQueue($notification, \App::$now, false);
45        \App::$log->debug("Send notification", [$notification]);
46
47        $message = Response\Message::create($request);
48        $message->data = $notification;
49
50        $response = Render::withLastModified($response, time(), '0');
51        $response = Render::withJson($response, $message, 200);
52        return $response;
53    }
54
55    protected function testProcessData($process)
56    {
57        $authCheck = (new Process())->readAuthKeyByProcessId($process->id);
58        if (! $authCheck) {
59            throw new Exception\Process\ProcessNotFound();
60        } elseif (! $process->getFirstClient()->hasTelephone()) {
61            throw new Exception\Process\TelephoneRequired();
62        }
63    }
64}