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