| Conditions | 12 |
| Paths | 13 |
| Total Lines | 67 |
| Code Lines | 45 |
| 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 |
||
| 66 | public function createAction( |
||
| 67 | FormFactoryInterface $formFactory, |
||
| 68 | Request $request, |
||
| 69 | Session $session, |
||
| 70 | Command $taskCommand |
||
| 71 | ) { |
||
| 72 | try { |
||
| 73 | $createTaskForm = $formFactory->create(CreateTaskForm::class); |
||
| 74 | } catch (InvalidOptionsException $e) { |
||
| 75 | try { |
||
| 76 | $this->addFlash('error', $e->getMessage()); |
||
| 77 | } catch (\LogicException $e) { |
||
| 78 | throw $e; |
||
| 79 | } |
||
| 80 | return $this->redirectToRoute('task.create'); |
||
| 81 | } |
||
| 82 | |||
| 83 | $createTaskForm->handleRequest($request); |
||
| 84 | if ($createTaskForm->isSubmitted() && $createTaskForm->isValid()) { |
||
| 85 | try { |
||
| 86 | $name = $createTaskForm->getData()['name']; |
||
| 87 | $this->addFlash('form_name', $name); |
||
| 88 | } catch (\OutOfBoundsException $e) { |
||
| 89 | try { |
||
| 90 | $this->addFlash('error', $e->getMessage()); |
||
| 91 | } catch (\LogicException $e) { |
||
| 92 | throw $e; |
||
| 93 | } |
||
| 94 | return $this->redirectToRoute('task.create'); |
||
| 95 | } |
||
| 96 | |||
| 97 | try { |
||
| 98 | $taskCommand->addNewTask($name); |
||
| 99 | } catch (TaskNameIsEmptyException | TaskNameIsAlreadyExistedException | TaskCannotBeSavedException $e) { |
||
| 100 | try { |
||
| 101 | $this->addFlash('error', $e->getMessage()); |
||
| 102 | } catch (\LogicException $e) { |
||
| 103 | throw $e; |
||
| 104 | } |
||
| 105 | return $this->redirectToRoute('task.create'); |
||
| 106 | } |
||
| 107 | |||
| 108 | $formName = $session->getFlashBag()->set('form_name', null); |
||
|
|
|||
| 109 | return $this->redirectToRoute('task.list'); |
||
| 110 | |||
| 111 | |||
| 112 | } |
||
| 113 | |||
| 114 | if (count($formName = $session->getFlashBag()->get('form_name')) > 0) { |
||
| 115 | try { |
||
| 116 | $createTaskForm->get('name')->setData($formName[0]); |
||
| 117 | } catch (\OutOfBoundsException $e) { |
||
| 118 | try { |
||
| 119 | $this->addFlash('error', $e->getMessage()); |
||
| 120 | } catch (\LogicException $e) { |
||
| 121 | throw $e; |
||
| 122 | } |
||
| 123 | return $this->redirectToRoute('task.create'); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | |||
| 128 | |||
| 129 | return [ |
||
| 130 | 'create_task_form' => $createTaskForm->createView() |
||
| 131 | ]; |
||
| 132 | } |
||
| 133 | |||
| 228 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.