Passed
Pull Request — develop (#152)
by Laurent
01:25
created

UserModelMapper::getDataFromUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 6
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Administration\Infrastructure\User\Mapper;
15
16
use Administration\Application\User\ReadModel\User as UserReadModel;
17
use Administration\Domain\User\Model\User;
18
19
class UserModelMapper
20
{
21
    public function getReadModelFromArray(array $data): UserReadModel
22
    {
23
        return new UserReadModel(
24
            $data['uuid'],
25
            $data['username'],
26
            $data['email'],
27
            \explode(',', $data['roles']),
28
            null,
29
        );
30
    }
31
32
    public function getDataFromUser(User $user): array
33
    {
34
        return [
35
            'uuid' => $user->uuid()->toString(),
36
            'username' => $user->username(),
37
            'email' => $user->email()->getValue(),
38
            'password' => $user->password(),
39
            'roles' => \implode(',', $user->roles()),
40
        ];
41
    }
42
}
43