Lines 100.00% 14 / 14
Functions and Methods 100.00% 1 / 1
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
RoleUpdate 100.00% 14 / 14 100.00% 1 / 1 3 100.00% 1 / 1
 readResponse 100.00% 14 / 14 100.00% 1 / 1 3
1<?php
2
3namespace BO\Zmsbackend\Role\Api;
4
5use BO\Mellon\Validator;
6use BO\Slim\Render;
7use BO\Zmsbackend\Role\Service\Role;
8use BO\Zmsentities\Role as RoleEntity;
9
10class RoleUpdate extends \BO\Zmsbackend\Api\BaseController
11{
12    /**
13     * @return \Psr\Http\Message\ResponseInterface
14     */
15    #[\Override]
16    public function readResponse(
17        \Psr\Http\Message\RequestInterface $request,
18        \Psr\Http\Message\ResponseInterface $response,
19        array $args
20    ) {
21        (new \BO\Zmsbackend\Helper\User($request, 1))->checkPermissions('superuser');
22
23        $roleId = (int) $args['id'];
24        $input = Validator::input()->isJson()->assertValid()->getValue();
25        unset($input['id'], $input['assignedUserCount']);
26
27        $entity = new RoleEntity($input);
28        $entity->testValid();
29
30        $updated = (new \BO\Zmsbackend\Role\Service\Role())->updateRole($roleId, $entity);
31        if (!$updated || !$updated->hasId()) {
32            throw new \BO\Zmsbackend\Role\Exception\RoleDoesNotExist();
33        }
34
35        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
36        $message->data = $updated;
37
38        $response = Render::withLastModified($response, time(), '0');
39        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
40        return $response;
41    }
42}