Passed
Push — 1.0 ( 7bc273...e682a4 )
by Pol
06:25 queued 01:30
created

Logout::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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