| Conditions | 9 |
| Paths | 26 |
| Total Lines | 65 |
| Code Lines | 38 |
| 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 |
||
| 33 | public function confirmEmailAction(Request $request) |
||
| 34 | { |
||
| 35 | /** @var PersonInterface $person */ |
||
| 36 | $person = $this->getUser(); |
||
| 37 | $resend = $request->get('resend', false); |
||
| 38 | $notifySent = $request->get('resent', false); |
||
| 39 | $originalEmail = $person->getEmail(); |
||
| 40 | |||
| 41 | /** @var TaskStackManagerInterface $stackManager */ |
||
| 42 | $stackManager = $this->get('task_stack.manager'); |
||
| 43 | $targetUrl = $this->getTargetUrl($stackManager); |
||
| 44 | |||
| 45 | if ($person->getEmailConfirmedAt()) { |
||
| 46 | $task = $stackManager->getCurrentTask(); |
||
| 47 | |||
| 48 | if ($task instanceof ConfirmEmailTask) { |
||
| 49 | $stackManager->setTaskSkipped($task); |
||
| 50 | } |
||
| 51 | |||
| 52 | return $stackManager->processRequest($request, $this->redirect($targetUrl)); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** @var EventDispatcher $dispatcher */ |
||
| 56 | $dispatcher = $this->get('event_dispatcher'); |
||
| 57 | $event = new GetResponseUserEvent($person, $request); |
||
| 58 | $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event); |
||
| 59 | |||
| 60 | $form = $this->createForm('LoginCidadao\CoreBundle\Form\Type\EmailFormType', $person); |
||
| 61 | |||
| 62 | $response = null; |
||
| 63 | $form->handleRequest($request); |
||
| 64 | $emailChanged = false; |
||
| 65 | if ($form->isValid()) { |
||
| 66 | $emailChanged = $originalEmail !== $person->getEmail(); |
||
| 67 | if ($emailChanged) { |
||
| 68 | /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ |
||
| 69 | $userManager = $this->get('fos_user.user_manager'); |
||
| 70 | |||
| 71 | $event = new FormEvent($form, $request); |
||
| 72 | $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event); |
||
| 73 | |||
| 74 | $userManager->updateUser($person); |
||
| 75 | |||
| 76 | $response = $this->redirectToRoute('task_confirm_email', ['resent' => '✓']); |
||
| 77 | $event = new FilterUserResponseEvent($person, $request, $response); |
||
| 78 | $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, $event); |
||
| 79 | $response = $event->getResponse(); |
||
| 80 | } else { |
||
| 81 | $resend = true; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($emailChanged || $notifySent) { |
||
| 86 | $this->flashEmailSent(); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($resend) { |
||
| 90 | $this->resendEmailConfirmation($person); |
||
| 91 | } |
||
| 92 | |||
| 93 | if ($response instanceof Response) { |
||
| 94 | return $response; |
||
| 95 | } |
||
| 96 | |||
| 97 | return ['targetUrl' => $targetUrl, 'form' => $form->createView()]; |
||
| 98 | } |
||
| 174 |