| @@ 107-122 (lines=16) @@ | ||
| 104 | * @return string |
|
| 105 | * @throws \Exception |
|
| 106 | */ |
|
| 107 | public static function validateInputOnUpdateUser($input, $user) |
|
| 108 | { |
|
| 109 | if (!isset($input['name']) && !isset($input['email'])) { |
|
| 110 | throw new \Exception(Messages::USER_INFO_REQUIRED, 400); |
|
| 111 | } |
|
| 112 | $name = $user->name; |
|
| 113 | if (isset($input['name'])) { |
|
| 114 | $name = self::validateName($input['name']); |
|
| 115 | } |
|
| 116 | $email = $user->email; |
|
| 117 | if (isset($input['email'])) { |
|
| 118 | $email = self::validateEmail($input['email']); |
|
| 119 | } |
|
| 120 | ||
| 121 | return ['name' => $name, 'email' => $email]; |
|
| 122 | } |
|
| 123 | ||
| 124 | /** |
|
| 125 | * Validate and sanitize input data when create new task. |
|
| @@ 153-168 (lines=16) @@ | ||
| 150 | * @return string |
|
| 151 | * @throws \Exception |
|
| 152 | */ |
|
| 153 | public static function validateInputOnUpdateTask($input, $task) |
|
| 154 | { |
|
| 155 | if (!isset($input['task']) && !isset($input['status'])) { |
|
| 156 | throw new \Exception(Messages::TASK_INFO_REQUIRED, 400); |
|
| 157 | } |
|
| 158 | $name = $task->task; |
|
| 159 | if (isset($input['task'])) { |
|
| 160 | $name = self::validateTaskName($input['task']); |
|
| 161 | } |
|
| 162 | $status = $task->status; |
|
| 163 | if (isset($input['status'])) { |
|
| 164 | $status = self::validateStatus($input['status']); |
|
| 165 | } |
|
| 166 | ||
| 167 | return ['task' => $name, 'status' => $status]; |
|
| 168 | } |
|
| 169 | } |
|
| 170 | ||