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

CasUserProvider::loadUserByIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 3
b 0
f 0
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