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

SupplierModelMapper::getDomainModelFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 15
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 17
rs 9.7666
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\Supplier;
15
16
use Administration\Application\Supplier\ReadModel\Supplier as SupplierModel;
17
use Administration\Application\Supplier\ReadModel\Supplier as SupplierReadModel;
18
use Administration\Domain\Supplier\Model\Supplier;
19
use Core\Domain\Common\Model\Dependent\FamilyLog;
20
use Core\Domain\Common\Model\VO\ContactUuid;
21
use Core\Domain\Common\Model\VO\EmailField;
22
use Core\Domain\Common\Model\VO\NameField;
23
use Core\Domain\Common\Model\VO\PhoneField;
24
25
class SupplierModelMapper
26
{
27
    public function getReadModelFromArray(array $data): SupplierReadModel
28
    {
29
        return new SupplierModel(
30
            $data['uuid'],
31
            $data['name'],
32
            $data['address'],
33
            $data['zip_code'],
34
            $data['town'],
35
            $data['country'],
36
            $data['phone'],
37
            $data['facsimile'],
38
            $data['email'],
39
            $data['contact_name'],
40
            $data['cellphone'],
41
            $data['family_log'],
42
            (int) $data['delay_delivery'],
43
            \explode(',', $data['order_days']),
44
            $data['slug'],
45
            $data['active']
46
        );
47
    }
48
49
    public function getDomainModelFromArray(array $data): Supplier
50
    {
51
        return Supplier::create(
52
            ContactUuid::fromString($data['uuid']),
53
            NameField::fromString($data['name']),
54
            $data['address'],
55
            $data['zip_code'],
56
            $data['town'],
57
            $data['country'],
58
            PhoneField::fromString($data['phone']),
59
            PhoneField::fromString($data['facsimile']),
60
            EmailField::fromString($data['email']),
61
            $data['contact_name'],
62
            PhoneField::fromString($data['cellphone']),
63
            FamilyLog::create(NameField::fromString($data['family_log'])),
64
            (int) $data['delay_delivery'],
65
            \explode(',', $data['order_days']),
66
        );
67
    }
68
69
    public function getDataFromSupplier(Supplier $supplier): array
70
    {
71
        return [
72
            'uuid' => $supplier->uuid(),
73
            'name' => $supplier->name(),
74
            'address' => $supplier->address(),
75
            'zip_code' => $supplier->zipCode(),
76
            'town' => $supplier->town(),
77
            'country' => $supplier->country(),
78
            'phone' => $supplier->phone(),
79
            'facsimile' => $supplier->facsimile(),
80
            'email' => $supplier->email(),
81
            'contact_name' => $supplier->contact(),
82
            'cellphone' => $supplier->cellphone(),
83
            'family_log' => $supplier->familyLog(),
84
            'delay_delivery' => $supplier->delayDelivery(),
85
            'order_days' => \implode(',', $supplier->orderDays()),
86
            'slug' => $supplier->slug(),
87
            'active' => (int) $supplier->isActive(),
88
        ];
89
    }
90
}
91