GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

StorageUserProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A loadUserByApiKey() 0 13 3
A __construct() 0 3 1
A loadUserByUsername() 0 3 1
A supportsClass() 0 3 1
A refreshUser() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Security\ApiKey;
6
7
use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFound;
8
use Damax\Bundle\ApiAuthBundle\Key\Storage\Reader as Storage;
9
use Damax\Bundle\ApiAuthBundle\Security\ApiUser;
10
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
11
use Symfony\Component\Security\Core\User\UserInterface;
12
13
final class StorageUserProvider implements ApiKeyUserProvider
14
{
15
    private $storage;
16
17
    public function __construct(Storage $storage)
18
    {
19
        $this->storage = $storage;
20
    }
21
22
    public function supportsClass($class): bool
23
    {
24
        return ApiUser::class === $class;
25
    }
26
27
    public function loadUserByUsername($username): UserInterface
28
    {
29
        return new ApiUser($username);
30
    }
31
32
    public function loadUserByApiKey(string $apiKey): UserInterface
33
    {
34
        try {
35
            $key = $this->storage->get($apiKey);
36
        } catch (KeyNotFound $e) {
37
            throw new InvalidApiKey();
38
        }
39
40
        if ($key->expired()) {
41
            throw new InvalidApiKey();
42
        }
43
44
        return $this->loadUserByUsername($key->identity());
45
    }
46
47
    /**
48
     * @throws UnsupportedUserException
49
     */
50
    public function refreshUser(UserInterface $user): UserInterface
51
    {
52
        throw new UnsupportedUserException(sprintf('Provider "%s" must be configured as stateless.', __CLASS__));
53
    }
54
}
55