ResettingListener   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A onResettingResetInitialize() 0 8 1
A onResettingSendEmailInitialize() 0 11 3
A onResettingSendEmailCompleted() 0 4 1
A __construct() 0 4 1
A getSubscribedEvents() 0 7 1
A onResettingResetSuccess() 0 4 1
1
<?php
2
3
namespace App\EventListener;
4
5
use FOS\UserBundle\Event\FormEvent;
0 ignored issues
show
Bug introduced by
The type FOS\UserBundle\Event\FormEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use FOS\UserBundle\Event\GetResponseNullableUserEvent;
0 ignored issues
show
Bug introduced by
The type FOS\UserBundle\Event\GetResponseNullableUserEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use FOS\UserBundle\Event\GetResponseUserEvent;
0 ignored issues
show
Bug introduced by
The type FOS\UserBundle\Event\GetResponseUserEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use FOS\UserBundle\FOSUserEvents;
0 ignored issues
show
Bug introduced by
The type FOS\UserBundle\FOSUserEvents was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use stdClass;
10
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...tion\ContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\EventD...ventSubscriberInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Symfony\Component\HttpFoundation\JsonResponse;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\JsonResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Symfony\Component\HttpFoundation\RequestStack;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\RequestStack was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Symfony\Component\HttpFoundation\Response;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
/**
17
 * Class ResettingListener
18
 */
19
final class ResettingListener implements EventSubscriberInterface
20
{
21
    /**
22
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
23
     */
24
    private $container;
25
26
    /**
27
     * @var \Symfony\Component\HttpFoundation\RequestStack
28
     */
29
    private $requestStack;
30
31
    /**
32
     * Constructor
33
     *
34
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
35
     * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
36
     */
37
    public function __construct(ContainerInterface $container, RequestStack $requestStack)
38
    {
39
        $this->container = $container;
40
        $this->requestStack = $requestStack;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public static function getSubscribedEvents()
47
    {
48
        return [
49
            FOSUserEvents::RESETTING_SEND_EMAIL_INITIALIZE => 'onResettingSendEmailInitialize',
50
            FOSUserEvents::RESETTING_SEND_EMAIL_COMPLETED => 'onResettingSendEmailCompleted',
51
            FOSUserEvents::RESETTING_RESET_INITIALIZE => 'onResettingResetInitialize',
52
            FOSUserEvents::RESETTING_RESET_SUCCESS => 'onResettingResetSuccess'
53
        ];
54
    }
55
56
    /**
57
     * Return an empty json response if the user does not exist.
58
     *
59
     * @param \FOS\UserBundle\Event\GetResponseNullableUserEvent $event
60
     */
61
    public function onResettingSendEmailInitialize(GetResponseNullableUserEvent $event)
62
    {
63
        $user = $event->getUser();
64
        $ttl = $this->container->getParameter('fos_user.resetting.retry_ttl');
65
66
        if (null !== $user && !$user->isPasswordRequestNonExpired($ttl)) {
67
            return;
68
        }
69
70
        $response = new JsonResponse(new stdClass, Response::HTTP_CREATED);
71
        $event->setResponse($response);
72
    }
73
74
    /**
75
     * Return an empty json response once email has been sent.
76
     *
77
     * @param \FOS\UserBundle\Event\GetResponseUserEvent $event
78
     */
79
    public function onResettingSendEmailCompleted(GetResponseUserEvent $event)
80
    {
81
        $response = new JsonResponse(new stdClass, Response::HTTP_CREATED);
82
        $event->setResponse($response);
83
    }
84
85
    /**
86
     * Convert password input to password confirmation input.
87
     *
88
     * @param \FOS\UserBundle\Event\GetResponseUserEvent $event
89
     */
90
    public function onResettingResetInitialize(GetResponseUserEvent $event)
91
    {
92
        $request = $this->requestStack->getCurrentRequest();
93
        $password = $request->request->get('password');
94
        $request->request->set('fos_user_resetting_form', [
95
            'plainPassword' => [
96
                'first' => $password,
97
                'second' => $password
98
            ]
99
        ]);
100
    }
101
102
    public function onResettingResetSuccess(FormEvent $event)
103
    {
104
        $response = new JsonResponse(new stdClass, Response::HTTP_CREATED);
105
        $event->setResponse($response);
106
    }
107
}
108