Passed
Push — feature/configure_company ( 5f97ab...38f251 )
by Laurent
03:30 queued 10s
created

Supplier::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 30
c 0
b 0
f 0
rs 9.8333
cc 1
nc 1
nop 15

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