Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
GetAuthenticatedRolesEndpoint | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
handle | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace Olz\Api\Endpoints; |
4 | |
5 | use Olz\Api\OlzTypedEndpoint; |
6 | |
7 | /** |
8 | * @phpstan-type OlzAuthenticatedRole array{ |
9 | * id: int, |
10 | * name: non-empty-string, |
11 | * username: non-empty-string, |
12 | * } |
13 | * |
14 | * @extends OlzTypedEndpoint< |
15 | * ?array{}, |
16 | * array{ |
17 | * roles?: ?array<OlzAuthenticatedRole> |
18 | * } |
19 | * > |
20 | */ |
21 | class GetAuthenticatedRolesEndpoint extends OlzTypedEndpoint { |
22 | protected function handle(mixed $input): mixed { |
23 | $roles = $this->authUtils()->getAuthenticatedRoles(); |
24 | if ($roles === null) { |
25 | return ['roles' => null]; |
26 | } |
27 | return [ |
28 | 'roles' => array_map(function ($role) { |
29 | return [ |
30 | 'id' => $role->getId() ?? 0, |
31 | 'name' => $role->getName() ?: '-', |
32 | 'username' => $role->getUsername() ?: '-', |
33 | ]; |
34 | }, $roles), |
35 | ]; |
36 | } |
37 | } |