Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| AuthenticatedUserFinder | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOrFail | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Identity\Application; |
| 6 | |
| 7 | use App\Identity\Domain\Exceptions\UserNotFound; |
| 8 | use App\Identity\Domain\User; |
| 9 | use App\Identity\Domain\UserRepository; |
| 10 | use App\Identity\Domain\ValueObject\UserId; |
| 11 | |
| 12 | /** |
| 13 | * Loads the account behind a JWT. A user only ever acts on their own account |
| 14 | * (the id comes from the token), so a missing user is "not found", never a leak. |
| 15 | */ |
| 16 | final readonly class AuthenticatedUserFinder |
| 17 | { |
| 18 | public function __construct( |
| 19 | private UserRepository $users, |
| 20 | ) { |
| 21 | } |
| 22 | |
| 23 | public function getOrFail(UserId $id): User |
| 24 | { |
| 25 | $user = $this->users->ofId($id); |
| 26 | |
| 27 | if ($user === null) { |
| 28 | throw UserNotFound::of($id); |
| 29 | } |
| 30 | |
| 31 | return $user; |
| 32 | } |
| 33 | } |