Lines
94.44%
17 / 18
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| SessionUpdate | 94.44% | 17 / 18 | 50.00% | 1 / 2 | 8.01 | 0.00% | 0 / 1 | |||
| readResponse | 91.66% | 11 / 12 | 0.00% | 0 / 1 | 4.01 | |||||
| testMatching | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 4 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ZMS API | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsbackend\Session\Api; | |
| 9 | ||
| 10 | use BO\Slim\Render; | |
| 11 | use BO\Mellon\Validator; | |
| 12 | use BO\Zmsbackend\Session\Service\Session; | |
| 13 | ||
| 14 | class SessionUpdate extends \BO\Zmsbackend\Api\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 = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 38 | $message->data = (new \BO\Zmsbackend\Session\Service\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 | /** | |
| 46 | * @return void | |
| 47 | */ | |
| 48 | protected function testMatching(\BO\Zmsentities\Session $session) | |
| 49 | { | |
| 50 | if (false === \BO\Zmsbackend\Helper\Matching::isProviderExisting($session)) { | |
| 51 | throw new \BO\Zmsbackend\Matching\Exception\ProviderNotFound(); | |
| 52 | } elseif (false === \BO\Zmsbackend\Helper\Matching::isRequestExisting($session)) { | |
| 53 | throw new \BO\Zmsbackend\Matching\Exception\RequestNotFound(); | |
| 54 | } elseif (false === \BO\Zmsbackend\Helper\Matching::hasProviderRequest($session)) { | |
| 55 | throw new \BO\Zmsbackend\Matching\Exception\MatchingNotFound(); | |
| 56 | } | |
| 57 | } | |
| 58 | } |