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