| Conditions | 6 |
| Paths | 5 |
| Total Lines | 17 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 3 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 33 | 1 | private function validateUserData(array $input, int $userId): User |
|
| 34 | 1 | { |
|
| 35 | $user = $this->getUserFromDb($userId); |
||
| 36 | $data = json_decode((string) json_encode($input), false); |
||
| 37 | 1 | if (!isset($data->name) && !isset($data->email)) { |
|
| 38 | throw new \App\Exception\UserException('Enter the data to update the user.', 400); |
||
| 39 | } |
||
| 40 | if (isset($data->name)) { |
||
| 41 | $user->updateName(self::validateUserName($data->name)); |
||
| 42 | } |
||
| 43 | if (isset($data->email) && $data->email !== $user->getEmail()) { |
||
| 44 | $this->userRepository->checkUserByEmail($data->email); |
||
| 45 | $user->updateEmail(self::validateEmail($data->email)); |
||
| 46 | } |
||
| 47 | $user->updateUpdatedAt(date('Y-m-d H:i:s')); |
||
| 48 | |||
| 49 | return $user; |
||
| 50 | } |
||
| 52 |