| @@ 62-77 (lines=16) @@ | ||
| 59 | * @return string |
|
| 60 | * @throws \Exception |
|
| 61 | */ |
|
| 62 | protected function validateInputOnUpdateUser($input, $user) |
|
| 63 | { |
|
| 64 | if (!isset($input['name']) && !isset($input['email'])) { |
|
| 65 | throw new \Exception(self::USER_INFO_REQUIRED, 400); |
|
| 66 | } |
|
| 67 | $name = $user->name; |
|
| 68 | if (isset($input['name'])) { |
|
| 69 | $name = $this->validateName($input['name']); |
|
| 70 | } |
|
| 71 | $email = $user->email; |
|
| 72 | if (isset($input['email'])) { |
|
| 73 | $email = $this->validateEmail($input['email']); |
|
| 74 | } |
|
| 75 | ||
| 76 | return ['name' => $name, 'email' => $email]; |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * Validate and sanitize input data when create new task. |
|
| @@ 100-115 (lines=16) @@ | ||
| 97 | return ['task' => $task, 'status' => $status]; |
|
| 98 | } |
|
| 99 | ||
| 100 | protected function validateInputOnUpdateTask($input, $task) |
|
| 101 | { |
|
| 102 | if (!isset($input['task']) && !isset($input['status'])) { |
|
| 103 | throw new \Exception(self::TASK_INFO_REQUIRED, 400); |
|
| 104 | } |
|
| 105 | $name = $task->task; |
|
| 106 | if (isset($input['task'])) { |
|
| 107 | $name = $this->validateTaskName($input['task']); |
|
| 108 | } |
|
| 109 | $status = $task->status; |
|
| 110 | if (isset($input['status'])) { |
|
| 111 | $status = $this->validateStatus($input['status']); |
|
| 112 | } |
|
| 113 | ||
| 114 | return ['task' => $name, 'status' => $status]; |
|
| 115 | } |
|
| 116 | ||
| 117 | /** |
|
| 118 | * Validate and sanitize a username. |
|