EuloginUserProvider::loadUserByResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\EuloginBundle\Security\Core\User;
6
7
use drupol\CasBundle\Security\Core\User\CasUserInterface;
8
use drupol\psrcas\Introspection\Introspector;
9
use Psr\Http\Message\ResponseInterface;
10
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
11
use Symfony\Component\Security\Core\User\UserInterface;
12
13
use function get_class;
14
15
/**
16
 * Class EuloginUserProvider.
17
 */
18
class EuloginUserProvider implements EuloginUserProviderInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function loadUserByResponse(ResponseInterface $response): CasUserInterface
24
    {
25
        /** @var \drupol\psrcas\Introspection\Contract\ServiceValidate $introspect */
26
        $introspect = Introspector::detect($response);
27
28
        return new EuloginUser($introspect->getParsedResponse()['serviceResponse']['authenticationSuccess']);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function loadUserByUsername(string $username)
35
    {
36
        throw new UnsupportedUserException(sprintf('Username "%s" does not exist.', $username));
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function refreshUser(UserInterface $user)
43
    {
44
        if (!$user instanceof EuloginUserInterface) {
45
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
46
        }
47
48
        return $user;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function supportsClass(string $class)
55
    {
56
        return EuloginUser::class === $class;
57
    }
58
}
59