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 String
19     */
20    public function readResponse(
21        \Psr\Http\Message\RequestInterface $request,
22        \Psr\Http\Message\ResponseInterface $response,
23        array $args
24    ) {
25        $input = Validator::input()->isJson()->assertValid()->getValue();
26        $session = new \BO\Zmsentities\Session($input);
27        //overwrite sessions content without frontend parameter like basket and human
28        if (Validator::param('oidc')->isBool()->setDefault(false)->getValue()) {
29            $session->content = $input['content'];
30        }
31        $session->testValid();
32        if (isset($session->getContent()['error']) && 'isDifferent' != $session->getContent()['error']) {
33            $this->testMatching($session);
34        }
35
36        $message = Response\Message::create($request);
37        $message->data = (new Session())->updateEntity($session);
38
39        $response = Render::withLastModified($response, time(), '0');
40        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
41        return $response;
42    }
43
44    protected function testMatching($session)
45    {
46        if (false === Helper\Matching::isProviderExisting($session)) {
47            throw new Exception\Matching\ProviderNotFound();
48        } elseif (false === Helper\Matching::isRequestExisting($session)) {
49            throw new Exception\Matching\RequestNotFound();
50        } elseif (false === Helper\Matching::hasProviderRequest($session)) {
51            throw new Exception\Matching\MatchingNotFound();
52        }
53    }
54}