Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.44% covered (success)
94.44%
17 / 18
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SessionUpdate
94.44% covered (success)
94.44%
17 / 18
50.00% covered (danger)
50.00%
1 / 2
8.01
0.00% covered (danger)
0.00%
0 / 1
 readResponse
91.67% covered (success)
91.67%
11 / 12
0.00% covered (danger)
0.00%
0 / 1
4.01
 testMatching
100.00% covered (success)
100.00%
6 / 6
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\Mellon\Validator;
12use BO\Zmsdb\Session;
13
14class SessionUpdate extends BaseController
15{
16    /**
17     * @SuppressWarnings(Param)
18     * @return \Psr\Http\Message\ResponseInterface
19     */
20    #[\Override]
21    public function readResponse(
22        \Psr\Http\Message\RequestInterface $request,
23        \Psr\Http\Message\ResponseInterface $response,
24        array $args
25    ) {
26        $input = Validator::input()->isJson()->assertValid()->getValue();
27        $session = new \BO\Zmsentities\Session($input);
28        //overwrite sessions content without frontend parameter like basket and human
29        if (Validator::param('oidc')->isBool()->setDefault(false)->getValue()) {
30            $session->content = $input['content'];
31        }
32        $session->testValid();
33        if (isset($session->getContent()['error']) && 'isDifferent' != $session->getContent()['error']) {
34            $this->testMatching($session);
35        }
36
37        $message = Response\Message::create($request);
38        $message->data = (new Session())->updateEntity($session);
39
40        $response = Render::withLastModified($response, time(), '0');
41        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
42        return $response;
43    }
44
45    protected function testMatching($session)
46    {
47        if (false === Helper\Matching::isProviderExisting($session)) {
48            throw new Exception\Matching\ProviderNotFound();
49        } elseif (false === Helper\Matching::isRequestExisting($session)) {
50            throw new Exception\Matching\RequestNotFound();
51        } elseif (false === Helper\Matching::hasProviderRequest($session)) {
52            throw new Exception\Matching\MatchingNotFound();
53        }
54    }
55}