benIT /
e-media
| 1 | <?php |
||
| 2 | |||
| 3 | namespace AppUserBundle\Controller; |
||
| 4 | |||
| 5 | use Symfony\Component\HttpFoundation\RedirectResponse; |
||
| 6 | use FOS\UserBundle\Controller\RegistrationController as BaseController; |
||
| 7 | use Symfony\Component\HttpFoundation\Request; |
||
| 8 | use FOS\UserBundle\Event\GetResponseUserEvent; |
||
| 9 | use FOS\UserBundle\FOSUserEvents; |
||
| 10 | use FOS\UserBundle\Event\FormEvent; |
||
| 11 | use FOS\UserBundle\Event\FilterUserResponseEvent; |
||
| 12 | |||
| 13 | class RegistrationController extends BaseController |
||
| 14 | { |
||
| 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()) { |
||
|
0 ignored issues
–
show
|
|||
| 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()) { |
||
|
0 ignored issues
–
show
Are you sure the assignment to
$response is correct as $event->getResponse() targeting FOS\UserBundle\Event\FormEvent::getResponse() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 67 | return $response; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | return $this->render('@FOSUser/Registration/register.html.twig', array( |
||
| 72 | 'form' => $form->createView(), |
||
| 73 | )); |
||
| 74 | } |
||
| 75 | } |
||
| 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.