LoginFailureHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A onAuthenticationFailure() 0 6 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 * 
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 * 
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\AppBundle\Security;
14
15
use Symfony\Component\HttpFoundation\RedirectResponse;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\Routing\RouterInterface;
18
use Symfony\Component\Security\Core\Exception\AuthenticationException;
19
use Symfony\Component\Security\Core\Security;
20
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
21
22
/**
23
 * Class LoginFailureHandler
24
 *
25
 * @author  Adam Piotrowski <[email protected]>
26
 */
27
final class LoginFailureHandler implements AuthenticationFailureHandlerInterface
28
{
29
    /**
30
     * @var RouterInterface
31
     */
32
    private $router;
33
    
34
    /**
35
     * @var string
36
     */
37
    private $loginRoute;
38
    
39
    public function __construct(RouterInterface $router, string $loginRoute)
40
    {
41
        $this->router     = $router;
42
        $this->loginRoute = $loginRoute;
43
    }
44
    
45
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
46
    {
47
        $request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
48
        
49
        return new RedirectResponse($this->router->generate($this->loginRoute));
50
    }
51
}
52