Lines 100.00% 26 / 26
Methods 100.00% 3 / 3
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 readResponse 100.00% 13 / 13 100.00% 1 / 1 1
 testEntity 100.00% 10 / 10 100.00% 1 / 1 5
 [BO\Zmsbackend\Api\BaseController] __invoke 100.00% 3 / 3 100.00% 1 / 1 1
14class UseraccountAdd 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        (new \BO\Zmsbackend\Helper\User($request, $resolveReferences))->checkPermissions('useraccount');
28        $input = Validator::input()->isJson()->assertValid()->getValue();
29
30        $entity = new \BO\Zmsentities\Useraccount($input);
31        $this->testEntity($entity, $input);
32        \BO\Zmsbackend\Helper\User::testWorkstationAssignedRoles($entity);
33        \BO\Zmsbackend\Helper\User::testWorkstationAccessRights($entity);
34        $entity->password = $entity->getHash($entity->password);
35
36        $message = \BO\Zmsbackend\Api\Response\Message::create($request);
37        $message->data = (new \BO\Zmsbackend\Useraccount\Service\Useraccount())->writeEntity($entity, $resolveReferences);
38
39        $response = Render::withLastModified($response, time(), '0');
40        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
41        return $response;
42    }
43
44    /**
45     * @return void
46     */
47    protected function testEntity(\BO\Zmsentities\Useraccount $entity, $input)
48    {
49        if (0 == count($input)) {
50            throw new \BO\Zmsbackend\Useraccount\Exception\UseraccountInvalidInput();
51        }
52        if (!isset($entity['departments'])) {
53            $entity->departments = [];
54        }
55        try {
56            $entity->testValid('de_DE', 1);
57        } catch (\Exception $exception) {
58            $exception->data['input'] = $input;
59            throw $exception;
60        }
61
62        if ((new \BO\Zmsbackend\Useraccount\Service\Useraccount())->readIsUserExisting($entity->id)) {
63            throw new \BO\Zmsbackend\Useraccount\Exception\UseraccountAlreadyExists();
64        }
65    }
66}

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    }