Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
AuthenticatedUserFinder
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getOrFail
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Identity\Application;
6
7use App\Identity\Domain\Exceptions\UserNotFound;
8use App\Identity\Domain\User;
9use App\Identity\Domain\UserRepository;
10use 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 */
16final 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}