Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
UseraccountAdd | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
testEntity | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | /** |
4 | * @package ZMS API |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsapi; |
9 | |
10 | use BO\Slim\Render; |
11 | use BO\Mellon\Validator; |
12 | use BO\Zmsdb\Useraccount; |
13 | |
14 | class UseraccountAdd extends BaseController |
15 | { |
16 | /** |
17 | * @SuppressWarnings(Param) |
18 | * @return String |
19 | */ |
20 | public function readResponse( |
21 | \Psr\Http\Message\RequestInterface $request, |
22 | \Psr\Http\Message\ResponseInterface $response, |
23 | array $args |
24 | ) { |
25 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(2)->getValue(); |
26 | (new Helper\User($request, $resolveReferences))->checkRights('useraccount'); |
27 | $input = Validator::input()->isJson()->assertValid()->getValue(); |
28 | |
29 | $entity = new \BO\Zmsentities\Useraccount($input); |
30 | $this->testEntity($entity, $input); |
31 | Helper\User::testWorkstationAccessRights($entity); |
32 | $entity->password = $entity->getHash($entity->password); |
33 | |
34 | $message = Response\Message::create($request); |
35 | $message->data = (new Useraccount())->writeEntity($entity, $resolveReferences); |
36 | |
37 | $response = Render::withLastModified($response, time(), '0'); |
38 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); |
39 | return $response; |
40 | } |
41 | |
42 | protected function testEntity($entity, $input) |
43 | { |
44 | if (0 == count($input)) { |
45 | throw new Exception\Useraccount\UseraccountInvalidInput(); |
46 | } |
47 | try { |
48 | $entity->testValid('de_DE', 1); |
49 | } catch (\Exception $exception) { |
50 | $exception->data['input'] = $input; |
51 | throw $exception; |
52 | } |
53 | |
54 | if ((new Useraccount())->readIsUserExisting($entity->id)) { |
55 | throw new Exception\Useraccount\UseraccountAlreadyExists(); |
56 | } |
57 | } |
58 | } |