TriggerController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
eloc 23
c 2
b 0
f 1
dl 0
loc 66
ccs 20
cts 20
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultAction() 0 25 3
A __construct() 0 13 1
1
<?php
2
3
namespace FlyingColours\TwilioTwoFactorBundle\Controller;
4
5
use FlyingColours\TwilioTwoFactorBundle\Model\Twilio\TwoFactorInterface;
6
use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorToken;
7
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
use Symfony\Component\EventDispatcher\GenericEvent;
10
use Symfony\Component\Form\FormInterface;
11
use Symfony\Component\HttpFoundation\RedirectResponse;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
14
use Symfony\Component\Routing\RouterInterface;
15
16
class TriggerController
17
{
18
    /** @var RouterInterface */
19
    private $router;
20
21
    /** @var EventDispatcherInterface */
22
    private $dispatcher;
23
24
    /** @var EngineInterface */
25
    private $templating;
26
27
    /** @var FormInterface */
28
    private $form;
29
30
    /** @var TwoFactorToken */
31
    private $token;
32
33
    /**
34
     * TriggerController constructor.
35
     *
36
     * @param RouterInterface $router
37
     * @param EventDispatcherInterface $dispatcher
38
     * @param EngineInterface $templating
39
     * @param FormInterface $form
40
     * @param TwoFactorToken $token
41
     */
42 2
    public function __construct(
43
        RouterInterface $router,
44
        EventDispatcherInterface $dispatcher,
45
        EngineInterface $templating,
46
        FormInterface $form,
47
        TwoFactorToken $token
48
    )
49
    {
50 2
        $this->router = $router;
51 2
        $this->dispatcher = $dispatcher;
52 2
        $this->templating = $templating;
53 2
        $this->form = $form;
54 2
        $this->token = $token;
55 2
    }
56
57 1
    public function defaultAction(Request $request)
58
    {
59 1
        $this->form->setData($this->token->getUser());
60
61 1
        $this->form->handleRequest($request);
62
63 1
        if ($this->form->isValid())
64
        {
65
            /** @var TwoFactorInterface $user */
66 1
            $user = $this->form->getData();
67
68
            /** @var GenericEvent $event */
69 1
            $event = $this->dispatcher->dispatch('twilio.auth.triggered', new GenericEvent($user));
0 ignored issues
show
Bug introduced by
'twilio.auth.triggered' of type string is incompatible with the type object expected by parameter $event of Symfony\Contracts\EventD...erInterface::dispatch(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

69
            $event = $this->dispatcher->dispatch(/** @scrutinizer ignore-type */ 'twilio.auth.triggered', new GenericEvent($user));
Loading history...
Unused Code introduced by
The call to Symfony\Contracts\EventD...erInterface::dispatch() has too many arguments starting with new Symfony\Component\Ev...her\GenericEvent($user). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
            /** @scrutinizer ignore-call */ 
70
            $event = $this->dispatcher->dispatch('twilio.auth.triggered', new GenericEvent($user));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
70
71 1
            $route = $event->hasArgument('route')
72 1
                ? $event->getArgument('route')
73 1
                : '2fa_login'
74
            ;
75
76 1
            return new RedirectResponse($this->router->generate($route));
77
        }
78
79 1
        return $this->templating->renderResponse(
80 1
            '@FlyingColoursTwilioTwoFactor/trigger/default.html.twig',
81 1
            [ 'form' => $this->form->createView() ]
82
        );
83
    }
84
}
85