| Conditions | 12 |
| Paths | 156 |
| Total Lines | 70 |
| Code Lines | 41 |
| 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 |
||
| 160 | public function updateAction( |
||
| 161 | FormFactoryInterface $formFactory, |
||
| 162 | Request $request, |
||
| 163 | Session $session, |
||
| 164 | Query $taskQuery, |
||
| 165 | Command $taskCommand, |
||
| 166 | $taskId |
||
| 167 | ) { |
||
| 168 | $errors = []; |
||
| 169 | try { |
||
| 170 | $task = $taskQuery->getTaskById($taskId); |
||
| 171 | } catch (TaskNotFoundException $e) { |
||
| 172 | $errors[] = $e->getMessage(); |
||
| 173 | } |
||
| 174 | |||
| 175 | if (count($errors) === 0) { |
||
| 176 | try { |
||
| 177 | $updateTaskForm = $formFactory->create( |
||
| 178 | UpdateTaskForm::class, |
||
| 179 | ($request->get('name') !== null) ? $request->request->all() : $task |
||
| 180 | ); |
||
| 181 | } catch (InvalidOptionsException $e) { |
||
| 182 | $errors[] = $e->getMessage(); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | if (count($errors) === 0) { |
||
| 187 | $updateTaskForm->handleRequest($request); |
||
| 188 | if ($updateTaskForm->isSubmitted() && $updateTaskForm->isValid()) { |
||
| 189 | try { |
||
| 190 | /** @var Task $task */ |
||
| 191 | $task = $updateTaskForm->getData(); |
||
| 192 | |||
| 193 | $name = $task->getName(); |
||
| 194 | $status = $task->getStatus(); |
||
| 195 | |||
| 196 | } catch (\OutOfBoundsException | \LogicException $e) { |
||
| 197 | $errors[] = $e->getMessage(); |
||
| 198 | } |
||
| 199 | |||
| 200 | if (count($errors) === 0) { |
||
| 201 | try { |
||
| 202 | $taskCommand->editTask( |
||
| 203 | $taskId, |
||
| 204 | [ |
||
| 205 | 'name' => $name, |
||
| 206 | 'status' => $status, |
||
| 207 | ] |
||
| 208 | ); |
||
| 209 | } catch (TaskNotFoundException | TaskNameIsEmptyException | TaskNameIsAlreadyExistedException | TaskCannotBeSavedException $e) { |
||
| 210 | $errors[] = $e->getMessage(); |
||
| 211 | |||
| 212 | } |
||
| 213 | } |
||
| 214 | |||
| 215 | if (count($errors) === 0) { |
||
| 216 | return $this->redirectToRoute('task.list'); |
||
| 217 | } |
||
| 218 | |||
| 219 | |||
| 220 | } |
||
| 221 | |||
| 222 | } |
||
| 223 | |||
| 224 | |||
| 225 | return [ |
||
| 226 | 'errors' => $errors, |
||
| 227 | 'update_task_form' => $updateTaskForm->createView() |
||
| 228 | ]; |
||
| 229 | } |
||
| 230 | |||
| 269 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.