Conditions | 4 |
Paths | 4 |
Total Lines | 20 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
30 | private function validateUserData(array $input): User |
||
31 | 1 | { |
|
32 | 1 | $data = json_decode((string) json_encode($input), false); |
|
33 | 1 | if (!isset($data->name)) { |
|
34 | throw new \App\Exception\UserException('The field "name" is required.', 400); |
||
35 | 1 | } |
|
36 | 1 | if (!isset($data->email)) { |
|
37 | throw new \App\Exception\UserException('The field "email" is required.', 400); |
||
38 | } |
||
39 | 1 | if (!isset($data->password)) { |
|
40 | throw new \App\Exception\UserException('The field "password" is required.', 400); |
||
41 | } |
||
42 | $user = new User(); |
||
43 | $user->updateName(self::validateUserName($data->name)); |
||
44 | $user->updateEmail(self::validateEmail($data->email)); |
||
45 | $user->updatePassword(hash('sha512', $data->password)); |
||
46 | $user->updateCreatedAt(date('Y-m-d H:i:s')); |
||
47 | $this->userRepository->checkUserByEmail($data->email); |
||
48 | |||
49 | return $user; |
||
50 | } |
||
52 |