Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
RoleUpdate
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
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    public function readResponse(
16        \Psr\Http\Message\RequestInterface $request,
17        \Psr\Http\Message\ResponseInterface $response,
18        array $args
19    ) {
20        (new \BO\Zmsbackend\Helper\User($request, 1))->checkPermissions('superuser');
21
22        $roleId = (int) $args['id'];
23        $input = Validator::input()->isJson()->assertValid()->getValue();
24        unset($input['id'], $input['assignedUserCount']);
25
26        $entity = new RoleEntity($input);
27        $entity->testValid();
28
29        $updated = (new \BO\Zmsbackend\Role\Service\Role())->updateRole($roleId, $entity);
30        if (!$updated || !$updated->hasId()) {
31            throw new \BO\Zmsbackend\Role\Exception\RoleDoesNotExist();
32        }
33
34        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
35        $message->data = $updated;
36
37        $response = Render::withLastModified($response, time(), '0');
38        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
39        return $response;
40    }
41}