| Conditions | 18 |
| Paths | 32 |
| Total Lines | 113 |
| Code Lines | 75 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 188 | public function updateAction( |
||
| 189 | FormFactoryInterface $formFactory, |
||
| 190 | Request $request, |
||
| 191 | Session $session, |
||
| 192 | Query $taskQuery, |
||
| 193 | Command $taskCommand, |
||
| 194 | $taskId |
||
| 195 | ) { |
||
| 196 | try { |
||
| 197 | $task = $taskQuery->getTaskById($taskId); |
||
| 198 | } catch (TaskNotFoundException $e) { |
||
| 199 | try { |
||
| 200 | $this->addFlash('error', $e->getMessage()); |
||
| 201 | } catch (\LogicException $e) { |
||
| 202 | throw $e; |
||
| 203 | } |
||
| 204 | return $this->redirectToRoute('task.update', [ 'taskId' => $taskId ]); |
||
| 205 | } |
||
| 206 | |||
| 207 | |||
| 208 | try { |
||
| 209 | $updateTaskForm = $formFactory->create( |
||
| 210 | UpdateTaskForm::class, |
||
| 211 | $task |
||
| 212 | ); |
||
| 213 | } catch (InvalidOptionsException $e) { |
||
| 214 | try { |
||
| 215 | $this->addFlash('error', $e->getMessage()); |
||
| 216 | } catch (\LogicException $e) { |
||
| 217 | throw $e; |
||
| 218 | } |
||
| 219 | return $this->redirectToRoute('task.update', [ 'taskId' => $taskId ]); |
||
| 220 | } |
||
| 221 | |||
| 222 | $updateTaskForm->handleRequest($request); |
||
| 223 | if ($updateTaskForm->isSubmitted() && $updateTaskForm->isValid()) { |
||
| 224 | try { |
||
| 225 | /** @var Task $task */ |
||
| 226 | $task = $updateTaskForm->getData(); |
||
| 227 | |||
| 228 | $name = $task->getName(); |
||
| 229 | $status = $task->getStatus(); |
||
| 230 | |||
| 231 | $this->addFlash('form_name', $name); |
||
| 232 | $this->addFlash('form_status', $status); |
||
| 233 | |||
| 234 | } catch (\OutOfBoundsException $e) { |
||
| 235 | try { |
||
| 236 | $this->addFlash('error', $e->getMessage()); |
||
| 237 | } catch (\LogicException $e) { |
||
| 238 | throw $e; |
||
| 239 | } |
||
| 240 | return $this->redirectToRoute('task.update', [ 'taskId' => $taskId ]); |
||
| 241 | } catch (\LogicException $e) { |
||
| 242 | throw $e; |
||
| 243 | } |
||
| 244 | |||
| 245 | try { |
||
| 246 | $taskCommand->editTask( |
||
| 247 | $taskId, |
||
| 248 | [ |
||
| 249 | 'name' => $name, |
||
| 250 | 'status' => $status, |
||
| 251 | ] |
||
| 252 | ); |
||
| 253 | } catch (TaskNotFoundException | TaskNameIsEmptyException | TaskNameIsAlreadyExistedException | TaskCannotBeSavedException $e) { |
||
| 254 | try { |
||
| 255 | $this->addFlash('error', $e->getMessage()); |
||
| 256 | } catch (\LogicException $e) { |
||
| 257 | throw $e; |
||
| 258 | } |
||
| 259 | return $this->redirectToRoute('task.update', [ 'taskId' => $taskId ]); |
||
| 260 | } |
||
| 261 | |||
| 262 | $session->getFlashBag()->set('form_name', null); |
||
| 263 | $session->getFlashBag()->set('form_status', null); |
||
| 264 | |||
| 265 | return $this->redirectToRoute('task.list'); |
||
| 266 | |||
| 267 | |||
| 268 | } |
||
| 269 | |||
| 270 | if (count($formName = $session->getFlashBag()->get('form_name')) > 0) { |
||
| 271 | try { |
||
| 272 | $updateTaskForm->get('name')->setData($formName[0]); |
||
| 273 | } catch (\OutOfBoundsException $e) { |
||
| 274 | try { |
||
| 275 | $this->addFlash('error', $e->getMessage()); |
||
| 276 | } catch (\LogicException $e) { |
||
| 277 | throw $e; |
||
| 278 | } |
||
| 279 | return $this->redirectToRoute('task.update', [ 'taskId' => $taskId ]); |
||
| 280 | } |
||
| 281 | } |
||
| 282 | |||
| 283 | if (count($formStatus = $session->getFlashBag()->get('form_status')) > 0) { |
||
| 284 | try { |
||
| 285 | $updateTaskForm->get('status')->setData($formStatus[0]); |
||
| 286 | } catch (\OutOfBoundsException $e) { |
||
| 287 | try { |
||
| 288 | $this->addFlash('error', $e->getMessage()); |
||
| 289 | } catch (\LogicException $e) { |
||
| 290 | throw $e; |
||
| 291 | } |
||
| 292 | return $this->redirectToRoute('task.update', [ 'taskId' => $taskId ]); |
||
| 293 | } |
||
| 294 | } |
||
| 295 | |||
| 296 | |||
| 297 | return [ |
||
| 298 | 'update_task_form' => $updateTaskForm->createView() |
||
| 299 | ]; |
||
| 300 | } |
||
| 301 | |||
| 340 |