Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProcessPreconfirm
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 1
 readResponse
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
6
 testProcessData
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
30
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\Process;
13
14/**
15 * @SuppressWarnings(CouplingBetweenObjects)
16 */
17class ProcessPreconfirm extends BaseController
18{
19    /**
20     * @SuppressWarnings(Param)
21     * @return String
22     */
23    public function readResponse(
24        \Psr\Http\Message\RequestInterface $request,
25        \Psr\Http\Message\ResponseInterface $response,
26        array $args
27    ) {
28        \BO\Zmsdb\Connection\Select::setCriticalReadSession();
29
30        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(3)->getValue();
31        $input = Validator::input()->isJson()->assertValid()->getValue();
32        $entity = new \BO\Zmsentities\Process($input);
33        $entity->testValid();
34        $this->testProcessData($entity);
35
36        $userAccount = (new Helper\User($request))->readWorkstation()->getUseraccount();
37        $process = (new Process())->readEntity($entity->id, $entity->authKey);
38        if ('reserved' != $process->status) {
39            throw new Exception\Process\ProcessNotReservedAnymore();
40        }
41
42        $process = (new Process())->updateProcessStatus(
43            $process,
44            'preconfirmed',
45            \App::$now,
46            $resolveReferences,
47            $userAccount
48        );
49        $message = Response\Message::create($request);
50        $message->data = $process;
51
52        $response = Render::withLastModified($response, time(), '0');
53        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
54        return $response;
55    }
56
57    protected function testProcessData($entity)
58    {
59        $authCheck = (new Process())->readAuthKeyByProcessId($entity->id);
60
61        if (! (new Process())->isAppointmentAllowedWithSameMail($entity)) {
62            throw new Exception\Process\MoreThanAllowedAppointmentsPerMail();
63        }
64
65        if (! $authCheck) {
66            throw new Exception\Process\ProcessNotFound();
67        } elseif ($authCheck['authKey'] != $entity->authKey && $authCheck['authName'] != $entity->authKey) {
68            throw new Exception\Process\AuthKeyMatchFailed();
69        }
70    }
71}