Passed
Pull Request — develop (#118)
by Laurent
05:08 queued 02:44
created

Supplier::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 29
c 0
b 0
f 0
rs 9.7998
cc 1
nc 1
nop 12

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