Completed
Pull Request — master (#9)
by
unknown
06:32
created

LogoutController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A logoutAction() 0 7 1
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\RedirectResponse;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\Routing\Router;
8
use Symfony\Component\Security\Core\SecurityContext;
9
10
final class LogoutController
11
{
12
    private $securityContext;
13
    private $router;
14
15
    /**
16
     * LogoutController constructor.
17
     *
18
     * @param SecurityContext $securityContext
19
     * @param Router $router
20
     */
21
    public function __construct(SecurityContext $securityContext, Router $router)
22
    {
23
        $this->securityContext = $securityContext;
24
        $this->router = $router;
25
    }
26
27
    /**
28
     * Logout user.
29
     *
30
     * @param Request $request
31
     *
32
     * @return RedirectResponse
33
     */
34
    public function logoutAction(Request $request)
35
    {
36
        $this->securityContext->setToken(null);
37
        $request->getSession()->invalidate();
38
39
        return new RedirectResponse($this->router->generate('login'));
40
    }
41
}
42