Lines 100.00% 12 / 12
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ProcessGet 100.00% 12 / 12 100.00% 2 / 2 4 100.00% 1 / 1
 readResponse 100.00% 7 / 7 100.00% 1 / 1 1
 testProcessData 100.00% 5 / 5 100.00% 1 / 1 3
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsbackend\Process\Api;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsbackend\Process\Service\Process;
13
14class ProcessGet 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        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(2)->getValue();
27        $this->testProcessData($args['id'], $args['authKey']);
28
29        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
30        $message->data = (new \BO\Zmsbackend\Process\Service\Process())->readEntity($args['id'], $args['authKey'], $resolveReferences);
31
32        $response = Render::withLastModified($response, time(), '0');
33        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
34        return $response;
35    }
36
37    /**
38     * @return void
39     */
40    protected function testProcessData($processId, $authKey)
41    {
42        $authCheck = (new \BO\Zmsbackend\Process\Service\Process())->readAuthKeyByProcessId($processId);
43        if (! $authCheck) {
44            throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound();
45        } elseif ($authCheck['authKey'] !== $authKey) {
46            throw new \BO\Zmsbackend\Process\Exception\AuthKeyMatchFailed();
47        }
48    }
49}