Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
UserMapper
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
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
 fromRow
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 toRow
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3// ╔════════════════════════════════════════════════════════════╗
4// ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║
5// ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com>     ║
6// ╚════════════════════════════════════════════════════════════╝
7
8declare(strict_types=1);
9
10namespace AppDemo\User\Infrastructure\Mapper;
11
12use AppDemo\User\Domain\Email;
13use AppDemo\User\Domain\HashedPassword;
14use AppDemo\User\Domain\User;
15use AppDemo\User\Domain\UserGroup;
16use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface;
17
18final readonly class UserMapper
19{
20    public function __construct(
21        private IdGeneratorInterface $idGenerator,
22    ) {}
23
24    public function fromRow(array $row): User
25    {
26        return new User(
27            $this->idGenerator->from($row['id']),
28            Email::fromString($row['email']),
29            HashedPassword::fromHash($row['password']),
30            UserGroup::from($row['group_name'])
31        );
32    }
33
34    public function toRow(User $user): array
35    {
36        return [
37            'id' => $user->getId()->getValue(),
38            'email' => $user->getEmail()->getValue(),
39            'password' => $user->getHashedPassword()->getValue(),
40            'group_name' => $user->getGroup()->value,
41        ];
42    }
43}