Lines 100.00% 45 / 45
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 readResponse 100.00% 42 / 42 100.00% 1 / 1 9
 [BO\Zmsbackend\Api\BaseController] __invoke 100.00% 3 / 3 100.00% 1 / 1 1
17class AppointmentUpdate extends \BO\Zmsbackend\Api\BaseController
18{
19    /**
20     * @SuppressWarnings(Param)
21     * @return \Psr\Http\Message\ResponseInterface
22     */
23    #[\Override]
24    public function readResponse(
25        \Psr\Http\Message\RequestInterface $request,
26        \Psr\Http\Message\ResponseInterface $response,
27        array $args
28    ) {
29        \BO\Zmsbackend\Connection\Select::setCriticalReadSession();
30
31        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue();
32        $slotsRequired = Validator::param('slotsRequired')->isNumber()->getValue();
33        $slotType = Validator::param('slotType')->isString()->getValue();
34        $clientKey = Validator::param('clientkey')->isString()->getValue();
35        $keepReserved = Validator::param('keepReserved')->isNumber()->setDefault(0)->getValue();
36        $input = Validator::input()->isJson()->assertValid()->getValue();
37        $appointment = new \BO\Zmsentities\Appointment($input);
38        $appointment->testValid();
39
40        // get old process and check user rights if slottype or slotrequired is set
41        $process = \BO\Zmsbackend\Process\Service\Process::init()->readEntity($args['id'], $args['authKey'], 1);
42        if (! $process->hasId()) {
43            throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound();
44        }
45        if ($slotType || $slotsRequired) {
46            (new \BO\Zmsbackend\Helper\User($request))->checkPermissions('appointment');
47            \BO\Zmsbackend\Helper\Matching::testCurrentScopeHasRequest($process);
48        } elseif ($clientKey) {
49            $apiClient = (new \BO\Zmsbackend\Apikey\Service\Apiclient())->readEntity($clientKey);
50            if (!$apiClient || !isset($apiClient->accesslevel) || $apiClient->accesslevel == 'blocked') {
51                throw new \BO\Zmsbackend\Process\Exception\ApiclientInvalid();
52            }
53            $slotType = $apiClient->accesslevel;
54            if ($apiClient->accesslevel != 'intern') {
55                $slotsRequired = 0;
56                $slotType = $apiClient->accesslevel;
57                $process = (new \BO\Zmsbackend\Process\Service\Process())->readSlotCount($process);
58            }
59            $process->apiclient = $apiClient;
60        } else {
61            $slotsRequired = 0;
62            $slotType = 'public';
63            $process = (new \BO\Zmsbackend\Process\Service\Process())->readSlotCount($process);
64        }
65
66        $process = \BO\Zmsbackend\Process\Service\Process::init()->writeEntityWithNewAppointment(
67            $process,
68            $appointment,
69            \App::$now,
70            $slotType,
71            $slotsRequired,
72            $resolveReferences,
73            ($keepReserved == 1)
74        );
75
76        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
77        $message->data = $process;
78
79        $response = Render::withLastModified($response, time(), '0');
80        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
81        return $response;
82    }
83}

Inherited from BO\Zmsbackend\Api\BaseController

20    public function __invoke(RequestInterface $request, ResponseInterface $response, array $args)
21    {
22        $request = $this->initRequest($request);
23        $noCacheResponse = \BO\Slim\Render::withLastModified($response, time(), '0');
24        return $this->readResponse($request, $noCacheResponse, $args);
25    }