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
GetCurrentUserHandler
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
 handle
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\Query;
6
7use App\Identity\Domain\UserRepository;
8use App\Identity\Domain\ValueObject\UserId;
9use App\Shared\Infrastructure\Storage\SignedImageUrl;
10
11final class GetCurrentUserHandler
12{
13    public function __construct(
14        private readonly UserRepository $users,
15        private readonly SignedImageUrl $imageUrls,
16    ) {
17    }
18
19    public function handle(GetCurrentUserQuery $query): ?CurrentUserView
20    {
21        $user = $this->users->ofId(new UserId($query->userId));
22
23        if ($user === null) {
24            return null;
25        }
26
27        return CurrentUserView::fromUser($user, $this->imageUrls->for($user->avatarName()));
28    }
29}