| Conditions | 6 |
| Paths | 6 |
| Total Lines | 58 |
| Code Lines | 30 |
| 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 |
||
| 15 | public function registerAction(Request $request) |
||
| 16 | { |
||
| 17 | /** @var $formFactory FactoryInterface */ |
||
| 18 | $formFactory = $this->get('fos_user.registration.form.factory'); |
||
| 19 | /** @var $userManager UserManagerInterface */ |
||
| 20 | $userManager = $this->get('fos_user.user_manager'); |
||
| 21 | /** @var $dispatcher EventDispatcherInterface */ |
||
| 22 | $dispatcher = $this->get('event_dispatcher'); |
||
| 23 | |||
| 24 | $user = $userManager->createUser(); |
||
| 25 | $user->setEnabled(true); |
||
| 26 | |||
| 27 | $event = new GetResponseUserEvent($user, $request); |
||
| 28 | $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event); |
||
| 29 | |||
| 30 | if (null !== $event->getResponse()) { |
||
| 31 | return $event->getResponse(); |
||
| 32 | } |
||
| 33 | |||
| 34 | $form = $formFactory->createForm(); |
||
| 35 | $form->setData($user); |
||
| 36 | |||
| 37 | $form->handleRequest($request); |
||
| 38 | |||
| 39 | if ($form->isSubmitted()) { |
||
| 40 | if ($form->isValid()) { |
||
| 41 | $event = new FormEvent($form, $request); |
||
| 42 | $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event); |
||
| 43 | |||
| 44 | $userManager->updateUser($user); |
||
| 45 | |||
| 46 | /***************************************************** |
||
| 47 | * Add new functionality (e.g. log the registration) * |
||
| 48 | *****************************************************/ |
||
| 49 | $this->container->get('logger')->info( |
||
| 50 | sprintf('New user registration: %s', $user) |
||
| 51 | ); |
||
| 52 | |||
| 53 | if (null === $response = $event->getResponse()) { |
||
| 54 | $url = $this->generateUrl('fos_user_registration_confirmed'); |
||
| 55 | $response = new RedirectResponse($url); |
||
| 56 | } |
||
| 57 | |||
| 58 | $dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response)); |
||
| 59 | |||
| 60 | return $response; |
||
| 61 | } |
||
| 62 | |||
| 63 | $event = new FormEvent($form, $request); |
||
| 64 | $dispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event); |
||
| 65 | |||
| 66 | if (null !== $response = $event->getResponse()) { |
||
| 67 | return $response; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | return $this->render('@FOSUser/Registration/register.html.twig', array( |
||
| 72 | 'form' => $form->createView(), |
||
| 73 | )); |
||
| 76 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.