Passed
Pull Request — develop (#155)
by Laurent
02:14
created

Supplier::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 15
dl 0
loc 34
rs 9.7333
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\Domain\Supplier\Model;
15
16
use Administration\Domain\FamilyLog\Model\FamilyLog;
17
use Core\Domain\Common\Model\Contact;
18
use Core\Domain\Common\Model\VO\ContactUuid;
19
use Core\Domain\Common\Model\VO\EmailField;
20
use Core\Domain\Common\Model\VO\NameField;
21
use Core\Domain\Common\Model\VO\PhoneField;
22
23
final class Supplier extends Contact
24
{
25
    protected string $uuid;
26
    private FamilyLog $familyLog;
27
    private int $delayDelivery;
28
    private array $orderDays;
29
    private bool $active;
30
31
    public function __construct(
32
        ContactUuid $uuid,
33
        NameField $name,
34
        string $address,
35
        string $zipCode,
36
        string $town,
37
        string $country,
38
        PhoneField $phone,
39
        PhoneField $facsimile,
40
        EmailField $email,
41
        string $contact,
42
        PhoneField $cellphone,
43
        FamilyLog $familyLog,
44
        int $delayDelivery,
45
        array $orderDays,
46
        bool $active = true
47
    ) {
48
        parent::__construct(
49
            $uuid,
50
            $name,
51
            $address,
52
            $zipCode,
53
            $town,
54
            $country,
55
            $phone,
56
            $facsimile,
57
            $email,
58
            $contact,
59
            $cellphone
60
        );
61
        $this->familyLog = $familyLog;
62
        $this->delayDelivery = $delayDelivery;
63
        $this->orderDays = $orderDays;
64
        $this->active = $active;
65
    }
66
67
    public static function create(
68
        ContactUuid $uuid,
69
        NameField $name,
70
        string $address,
71
        string $zipCode,
72
        string $town,
73
        string $country,
74
        PhoneField $phone,
75
        PhoneField $facsimile,
76
        EmailField $email,
77
        string $contact,
78
        PhoneField $gsm,
79
        FamilyLog $familyLog,
80
        int $delayDelivery,
81
        array $orderDays,
82
        bool $active = true
83
    ): self {
84
        return new self(
85
            $uuid,
86
            $name,
87
            $address,
88
            $zipCode,
89
            $town,
90
            $country,
91
            $phone,
92
            $facsimile,
93
            $email,
94
            $contact,
95
            $gsm,
96
            $familyLog,
97
            $delayDelivery,
98
            $orderDays,
99
            $active
100
        );
101
    }
102
103
    public function renameSupplier(NameField $name): void
104
    {
105
        $this->name = $name->getValue();
106
        $this->slug = $name->slugify();
107
    }
108
109
    public function familyLog(): FamilyLog
110
    {
111
        return $this->familyLog;
112
    }
113
114
    public function familyLogId(): string
115
    {
116
        return $this->familyLog->uuid();
117
    }
118
119
    public function reassignFamilyLog(FamilyLog $familyLog): void
120
    {
121
        $this->familyLog = $familyLog;
122
    }
123
124
    public function delayDelivery(): int
125
    {
126
        return $this->delayDelivery;
127
    }
128
129
    public function changeDelayDelivery(int $delayDelivery): void
130
    {
131
        $this->delayDelivery = $delayDelivery;
132
    }
133
134
    public function orderDays(): array
135
    {
136
        return $this->orderDays;
137
    }
138
139
    public function reassignOrderDays(array $orderDays): void
140
    {
141
        $this->orderDays = $orderDays;
142
    }
143
144
    public function isActive(): bool
145
    {
146
        return $this->active;
147
    }
148
149
    public function delete(): void
150
    {
151
        $this->active = false;
152
    }
153
}
154