| Total Complexity | 8 |
| Total Lines | 101 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | class ApiKeyUser implements ApiKeyUserInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @Groups({ |
||
| 27 | * "ApiKeyUser", |
||
| 28 | * "ApiKeyUser.apiKey", |
||
| 29 | * }) |
||
| 30 | */ |
||
| 31 | private string $username; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @Groups({ |
||
| 35 | * "ApiKeyUser.apiKey", |
||
| 36 | * }) |
||
| 37 | */ |
||
| 38 | private ApiKey $apiKey; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var array<int, string> |
||
| 42 | * |
||
| 43 | * @Groups({ |
||
| 44 | * "ApiKeyUser", |
||
| 45 | * "ApiKeyUser.roles", |
||
| 46 | * }) |
||
| 47 | */ |
||
| 48 | private array $roles; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritdoc} |
||
| 52 | */ |
||
| 53 | 34 | public function __construct(ApiKey $apiKey, array $roles) |
|
| 54 | { |
||
| 55 | 34 | $this->apiKey = $apiKey; |
|
| 56 | 34 | $this->username = $this->apiKey->getToken(); |
|
| 57 | 34 | $this->roles = array_unique(array_merge($roles, [RolesService::ROLE_API])); |
|
| 58 | 34 | } |
|
| 59 | |||
| 60 | 28 | public function getApiKey(): ApiKey |
|
| 61 | { |
||
| 62 | 28 | return $this->apiKey; |
|
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritdoc} |
||
| 67 | * |
||
| 68 | * @return array<int, string> The user roles |
||
| 69 | */ |
||
| 70 | 24 | public function getRoles(): array |
|
| 71 | { |
||
| 72 | 24 | return $this->roles; |
|
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * {@inheritdoc} |
||
| 77 | * |
||
| 78 | * @codeCoverageIgnore |
||
| 79 | */ |
||
| 80 | public function getPassword(): string |
||
| 81 | { |
||
| 82 | return ''; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * {@inheritdoc} |
||
| 87 | * |
||
| 88 | * @codeCoverageIgnore |
||
| 89 | */ |
||
| 90 | public function getSalt(): ?string |
||
| 91 | { |
||
| 92 | return null; |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * {@inheritdoc} |
||
| 97 | * |
||
| 98 | * @codeCoverageIgnore |
||
| 99 | */ |
||
| 100 | public function getUserIdentifier(): string |
||
| 101 | { |
||
| 102 | return $this->username; |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * {@inheritdoc} |
||
| 107 | * |
||
| 108 | * @codeCoverageIgnore |
||
| 109 | */ |
||
| 110 | public function eraseCredentials(): void |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @todo Remove this when this `getUsername` is removed from main interface (Symfony 6.0) |
||
| 116 | * |
||
| 117 | * {@inheritdoc} |
||
| 118 | * |
||
| 119 | * @codeCoverageIgnore |
||
| 120 | */ |
||
| 121 | public function getUsername(): string |
||
| 126 |