Passed
Pull Request — master (#59)
by Pol
14:21
created

CasUserProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 33
ccs 10
cts 12
cp 0.8333
rs 10
c 7
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsClass() 0 3 1
A refreshUser() 0 7 2
A loadUserByUsername() 0 3 1
A loadUserByIdentifier() 0 3 1
A loadUserByResponse() 0 7 2
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @see https://github.com/ecphp
8
 */
9
10
declare(strict_types=1);
11
12
namespace EcPhp\CasBundle\Security\Core\User;
13
14
use EcPhp\CasLib\Contract\Response\Type\ServiceValidate as TypeServiceValidate;
15
use Psr\Http\Message\ResponseInterface;
16
use Symfony\Component\Security\Core\Exception\AuthenticationException;
17
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
18
use Symfony\Component\Security\Core\User\UserInterface;
19
20
use function get_class;
21
22
final class CasUserProvider implements CasUserProviderInterface
23
{
24
    public function loadUserByIdentifier($identifier): UserInterface
0 ignored issues
show
Unused Code introduced by
The parameter $identifier is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
    public function loadUserByIdentifier(/** @scrutinizer ignore-unused */ $identifier): UserInterface

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        throw new UnsupportedUserException('Unsupported operation.');
27
    }
28 6
29
    public function loadUserByResponse(ResponseInterface $response): CasUserInterface
30 6
    {
31
        if ($response instanceof TypeServiceValidate) {
32
            return new CasUser($response->getCredentials());
33 2
        }
34
35
        throw new AuthenticationException('Unable to load user from response.');
36 2
    }
37
38
    public function loadUserByUsername(string $username): UserInterface
39
    {
40
        throw new UnsupportedUserException(sprintf('Username "%s" does not exist.', $username));
41 2
    }
42 2
43
    public function refreshUser(UserInterface $user): UserInterface
44
    {
45 2
        if (!$user instanceof CasUserInterface) {
46
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
47
        }
48 1
49
        return $user;
50 1
    }
51
52
    public function supportsClass(string $class): bool
53 1
    {
54
        return CasUser::class === $class;
55 1
    }
56
}
57