SecurityController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 7
c 5
b 0
f 2
lcom 1
cbo 4
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkAlreadyLogin() 0 16 4
A loginAction() 0 13 3
1
<?php
2
3
namespace DoS\UserBundle\Controller;
4
5
use Sylius\Bundle\UserBundle\Controller\SecurityController as BaseSecurityController;
6
use Symfony\Component\HttpFoundation\RedirectResponse;
7
use Symfony\Component\HttpFoundation\Request;
8
9
class SecurityController extends BaseSecurityController
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $alreadyLoginRoute;
15
16
    /**
17
     * @var string
18
     */
19
    protected $alreadyLoginUrl;
20
21
    /**
22
     * @var string
23
     */
24
    protected $firewallName = 'main';
25
26
    /**
27
     * @param Request $request
28
     *
29
     * @return RedirectResponse|void
30
     */
31
    protected function checkAlreadyLogin(Request $request)
32
    {
33
        if ($this->get('dos.user.security')->isLoggedIn()) {
34
            if ($this->alreadyLoginUrl) {
35
                return $this->redirect($this->alreadyLoginUrl);
36
            }
37
38
            if ($this->alreadyLoginRoute) {
39
                return $this->redirectToRoute($this->alreadyLoginRoute);
40
            }
41
42
            return $this->redirect($request->headers->get('referer', $request->getUriForPath('/')));
43
        }
44
45
        return;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function loginAction(Request $request)
52
    {
53
        if ($response = $this->checkAlreadyLogin($request)) {
54
            return $response;
55
        }
56
57
        $key = sprintf('_security.%s.target_path', $this->firewallName);
58
        if (!$request->getSession()->has($key)) {
59
            $request->getSession()->set($key, $request->headers->get('referer'));
60
        }
61
62
        return parent::loginAction($request);
63
    }
64
}
65