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\Zmsapi;
4
5use BO\Mellon\Validator;
6use BO\Slim\Render;
7use BO\Zmsdb\Role;
8use BO\Zmsentities\Role as RoleEntity;
9
10class RoleUpdate extends BaseController
11{
12    public function readResponse(
13        \Psr\Http\Message\RequestInterface $request,
14        \Psr\Http\Message\ResponseInterface $response,
15        array $args
16    ) {
17        (new Helper\User($request, 1))->checkPermissions('superuser');
18
19        $roleId = (int) $args['id'];
20        $input = Validator::input()->isJson()->assertValid()->getValue();
21        unset($input['id'], $input['assignedUserCount']);
22
23        $entity = new RoleEntity($input);
24        $entity->testValid();
25
26        $updated = (new Role())->updateRole($roleId, $entity);
27        if (!$updated || !$updated->hasId()) {
28            throw new Exception\Role\RoleDoesNotExist();
29        }
30
31        $message = Response\Message::create($request);
32        $message->data = $updated;
33
34        $response = Render::withLastModified($response, time(), '0');
35        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
36        return $response;
37    }
38}