Logout::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 11
ccs 4
cts 5
cp 0.8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.032
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\CasBundle\Controller;
6
7
use drupol\psrcas\CasInterface;
8
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
11
12
/**
13
 * Class Logout.
14
 */
15
final class Logout extends AbstractController
16
{
17
    /**
18
     * @param \drupol\psrcas\CasInterface $cas
19
     * @param \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokenStorage
20
     *
21
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
22
     */
23 1
    public function __invoke(
24
        CasInterface $cas,
25
        TokenStorageInterface $tokenStorage
26
    ) {
27 1
        if (null !== $response = $cas->logout()) {
28 1
            $tokenStorage->setToken();
29
30 1
            return new RedirectResponse($response->getHeaderLine('location'));
31
        }
32
33
        return new RedirectResponse('/');
34
    }
35
}
36