ApiKeyUser::eraseCredentials()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Security/ApiKeyUser.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Security;
10
11
use App\Entity\ApiKey;
12
use App\Enum\Role;
13
use App\Security\Interfaces\ApiKeyUserInterface;
14
use Symfony\Component\Security\Core\User\UserInterface;
15
use function array_unique;
16
17
/**
18
 * Class ApiKeyUser
19
 *
20
 * @package App\Security
21
 * @author TLe, Tarmo Leppänen <[email protected]>
22
 */
23
class ApiKeyUser implements ApiKeyUserInterface, UserInterface
24
{
25
    private readonly string $identifier;
26
    private readonly string $apiKeyIdentifier;
27
28
    /**
29
     * @var array<int, string>
30
     */
31
    private readonly array $roles;
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 20
    public function __construct(ApiKey $apiKey, array $roles)
37
    {
38 20
        $this->identifier = $apiKey->getToken();
0 ignored issues
show
Bug introduced by
The property identifier is declared read-only in App\Security\ApiKeyUser.
Loading history...
39 20
        $this->apiKeyIdentifier = $apiKey->getId();
0 ignored issues
show
Bug introduced by
The property apiKeyIdentifier is declared read-only in App\Security\ApiKeyUser.
Loading history...
40 20
        $this->roles = array_unique([...$roles, Role::API->value]);
0 ignored issues
show
Bug introduced by
The property roles is declared read-only in App\Security\ApiKeyUser.
Loading history...
41
    }
42
43 2
    public function getUserIdentifier(): string
44
    {
45 2
        return $this->identifier;
46
    }
47
48 7
    public function getApiKeyIdentifier(): string
49
    {
50 7
        return $this->apiKeyIdentifier;
51
    }
52
53 15
    public function getRoles(): array
54
    {
55 15
        return $this->roles;
56
    }
57
58
    /**
59
     * @codeCoverageIgnore
60
     */
61
    public function getPassword(): ?string
62
    {
63
        return null;
64
    }
65
66
    /**
67
     * @codeCoverageIgnore
68
     */
69
    public function getSalt(): ?string
70
    {
71
        return null;
72
    }
73
74
    /**
75
     * @codeCoverageIgnore
76
     */
77
    public function eraseCredentials(): void
78
    {
79
    }
80
}
81