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

SettingsModelMapper::getReadModelFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
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 9
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\Settings\Mapper;
15
16
use Administration\Application\Settings\ReadModel\Settings as SettingsReadModel;
17
use Administration\Domain\Settings\Model\Settings;
18
use Administration\Domain\Settings\Model\VO\Currency;
19
use Administration\Domain\Settings\Model\VO\Locale;
20
use Administration\Domain\Settings\Model\VO\SettingsUuid;
21
22
class SettingsModelMapper
23
{
24
    public function getReadModelFromArray(array $data): SettingsReadModel
25
    {
26
        $symbol = Currency::fromString($data['currency']);
27
28
        return new SettingsReadModel(
29
            $data['currency'],
30
            $data['locale'],
31
            $symbol->symbol(),
32
            $data['uuid']
33
        );
34
    }
35
36
    public function getDomainModelFromArray(array $data): Settings
37
    {
38
        return Settings::create(
39
            SettingsUuid::fromString($data['uuid']),
40
            Locale::fromString($data['locale']),
41
            Currency::fromString($data['currency'])
42
        );
43
    }
44
45
    public function getDataFromSettings(Settings $settings): array
46
    {
47
        return [
48
            'uuid' => $settings->uuid(),
49
            'locale' => $settings->locale(),
50
            'currency' => $settings->currency(),
51
        ];
52
    }
53
}
54