EuloginUserProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 7
c 3
b 0
f 0
dl 0
loc 39
ccs 0
cts 19
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A refreshUser() 0 7 2
A loadUserByResponse() 0 6 1
A loadUserByUsername() 0 3 1
A supportsClass() 0 3 1
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