Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ProcessIcs
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
11 / 11
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
4
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\Zmsdb\Process;
12use BO\Zmsdb\Config;
13use BO\Mellon\Validator;
14
15class ProcessIcs extends BaseController
16{
17    /**
18     * @SuppressWarnings(Param)
19     * @return String
20     */
21    public function readResponse(
22        \Psr\Http\Message\RequestInterface $request,
23        \Psr\Http\Message\ResponseInterface $response,
24        array $args
25    ) {
26        $status = Validator::param('status')->isNumber()->setDefault('appointment')->getValue();
27        $this->testProcessData($args['id'], $args['authKey']);
28        $process = (new Process())->readEntity($args['id'], $args['authKey'], 2);
29
30        $config = (new Config())->readEntity();
31        $templateProvider = new \BO\Zmsdb\Helper\MailTemplateProvider($process);
32        $ics = \BO\Zmsentities\Helper\Messaging::getMailIcs($process, $config, $status, null, null, $templateProvider);
33
34        $message = Response\Message::create($request);
35        $message->data = $ics;
36
37        $response = Render::withLastModified($response, time(), '0');
38        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
39        return $response;
40    }
41
42    protected function testProcessData($processId, $authKey)
43    {
44        $authCheck = (new Process())->readAuthKeyByProcessId($processId);
45        if (! $authCheck) {
46            throw new Exception\Process\ProcessNotFound();
47        } elseif ($authCheck['authKey'] != $authKey && $authCheck['authName'] != $authKey) {
48            throw new Exception\Process\AuthKeyMatchFailed();
49        }
50    }
51}