Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UserRepositoryMappingTrait
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 rowToUser
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 userToRow
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\Trait;
11
12use AppDemo\User\Domain\Email;
13use AppDemo\User\Domain\HashedPassword;
14use AppDemo\User\Domain\User;
15use AppDemo\User\Domain\UserGroup;
16
17trait UserRepositoryMappingTrait
18{
19    protected function rowToUser(array $row): User
20    {
21        return new User(
22            $this->idGenerator->from($row['id']),
23            Email::fromString($row['email']),
24            HashedPassword::fromHash($row['password']),
25            UserGroup::from($row['group_name'])
26        );
27    }
28
29    protected function userToRow(User $user): array
30    {
31        return [
32            'id' => $user->getId()->getValue(),
33            'email' => $user->getEmail()->getValue(),
34            'password' => $user->getHashedPassword()->getValue(),
35            'group_name' => $user->getGroup()->value,
36        ];
37    }
38}