Completed
Push — master ( ea5814...44cdb9 )
by Tarmo
15:40 queued 15:31
created

ApiKeyUser::getPassword()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\Security\Interfaces\ApiKeyUserInterface;
13
use Symfony\Component\Security\Core\User\UserInterface;
14
use function array_merge;
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 string $identifier;
26
    private ApiKey $apiKey;
27
28
    /**
29
     * @var array<int, string>
30
     */
31
    private array $roles;
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 34
    public function __construct(ApiKey $apiKey, array $roles)
37
    {
38 34
        $this->apiKey = $apiKey;
39 34
        $this->identifier = $this->apiKey->getToken();
40 34
        $this->roles = array_unique(array_merge($roles, [RolesService::ROLE_API]));
41 34
    }
42
43 28
    public function getApiKey(): ApiKey
44
    {
45 28
        return $this->apiKey;
46
    }
47
48 24
    public function getRoles(): array
49
    {
50 24
        return $this->roles;
51
    }
52
53
    /**
54
     * @codeCoverageIgnore
55
     */
56
    public function getPassword(): ?string
57
    {
58
        return null;
59
    }
60
61
    /**
62
     * @codeCoverageIgnore
63
     */
64
    public function getSalt(): ?string
65
    {
66
        return null;
67
    }
68
69
    /**
70
     * @codeCoverageIgnore
71
     */
72
    public function eraseCredentials(): void
73
    {
74
    }
75
76 3
    public function getUserIdentifier(): string
77
    {
78 3
        return $this->identifier;
79
    }
80
81
    /**
82
     * @todo Remove this method when Symfony 6.0.0 is released
83
     *
84
     * @codeCoverageIgnore
85
     */
86
    public function getUsername(): string
87
    {
88
        return $this->getUserIdentifier();
89
    }
90
}
91