RequestPasswordResetController::requestAction()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 29

Duplication

Lines 15
Ratio 51.72 %

Importance

Changes 0
Metric Value
dl 15
loc 29
rs 9.456
c 0
b 0
f 0
cc 4
nc 3
nop 1
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Controller;
4
5
use SumoCoders\FrameworkMultiUserBundle\Command\RequestPasswordResetHandler;
6
use SumoCoders\FrameworkMultiUserBundle\Exception\UserNotFound;
7
use SumoCoders\FrameworkMultiUserBundle\Form\RequestPasswordType;
8
use Symfony\Bundle\FrameworkBundle\Routing\Router;
9
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
10
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
11
use Symfony\Component\Form\FormFactoryInterface;
12
use Symfony\Component\HttpFoundation\RedirectResponse;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\HttpFoundation\Response;
15
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
16
17
final class RequestPasswordResetController
18
{
19
    /** @var EngineInterface */
20
    private $templating;
21
22
    /** @var FormFactoryInterface */
23
    private $formFactory;
24
25
    /** @var RequestPasswordResetHandler */
26
    private $requestPasswordResetHandler;
27
28
    /** @var Router */
29
    private $router;
30
31
    /** @var Translator */
32
    private $translator;
33
34
    /** @var FlashBagInterface */
35
    private $flashBag;
36
37 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
        EngineInterface $templating,
39
        FormFactoryInterface $formFactory,
40
        RequestPasswordResetHandler $requestPasswordResetHandler,
41
        Router $router,
42
        Translator $translator,
43
        FlashBagInterface $flashBag
44
    ) {
45
        $this->templating = $templating;
46
        $this->formFactory = $formFactory;
47
        $this->requestPasswordResetHandler = $requestPasswordResetHandler;
48
        $this->router = $router;
49
        $this->translator = $translator;
50
        $this->flashBag = $flashBag;
51
    }
52
53
    public function requestAction(Request $request): Response
54
    {
55
        $form = $this->formFactory->create(RequestPasswordType::class);
56
57
        $form->handleRequest($request);
58
59 View Code Duplication
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
            try {
61
                $this->requestPasswordResetHandler->handle($form->getData());
62
            } catch (UserNotFound $ignore) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
63
            }
64
65
            $this->flashBag->add(
66
                'success',
67
                $this->translator->trans(
68
                    'sumocoders.multiuserbundle.flash.password_reset_request_success'
69
                )
70
            );
71
72
            return new RedirectResponse($this->router->generate('multi_user_login'));
73
        }
74
75
        return $this->templating->renderResponse(
76
            'SumoCodersFrameworkMultiUserBundle:PasswordReset:request.html.twig',
77
            [
78
                'form' => $form->createView(),
79
            ]
80
        );
81
    }
82
}
83