Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| AdminUserView | |
100.00% |
23 / 23 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromUser | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Identity\Application\Query; |
| 6 | |
| 7 | use App\Identity\Domain\User; |
| 8 | use DateTimeInterface; |
| 9 | |
| 10 | /** |
| 11 | * Read model for the admin user listing. Never carries the password hash. |
| 12 | */ |
| 13 | final class AdminUserView |
| 14 | { |
| 15 | public function __construct( |
| 16 | public readonly string $id, |
| 17 | public readonly string $email, |
| 18 | public readonly string $name, |
| 19 | public readonly string $surnames, |
| 20 | public readonly string $preferredCurrency, |
| 21 | public readonly bool $isAdmin, |
| 22 | public readonly string $status, |
| 23 | public readonly string $createdAt, |
| 24 | // Signed, expiring URL of the user's photo, or null when they have none. |
| 25 | public readonly ?string $avatarUrl = null, |
| 26 | ) { |
| 27 | } |
| 28 | |
| 29 | public static function fromUser(User $user, ?string $avatarUrl = null): self |
| 30 | { |
| 31 | return new self( |
| 32 | $user->id()->value(), |
| 33 | $user->email()->value(), |
| 34 | $user->name(), |
| 35 | $user->surnames(), |
| 36 | $user->preferredCurrency()->code(), |
| 37 | $user->isAdmin(), |
| 38 | $user->status()->value, |
| 39 | $user->createdAt()->format(DateTimeInterface::ATOM), |
| 40 | $avatarUrl, |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return array<string, string|bool|null> |
| 46 | */ |
| 47 | public function toArray(): array |
| 48 | { |
| 49 | return [ |
| 50 | 'id' => $this->id, |
| 51 | 'email' => $this->email, |
| 52 | 'name' => $this->name, |
| 53 | 'surnames' => $this->surnames, |
| 54 | 'preferredCurrency' => $this->preferredCurrency, |
| 55 | 'isAdmin' => $this->isAdmin, |
| 56 | 'status' => $this->status, |
| 57 | 'createdAt' => $this->createdAt, |
| 58 | 'avatarUrl' => $this->avatarUrl, |
| 59 | ]; |
| 60 | } |
| 61 | } |