Completed
Push — main ( fffb13...d8afdd )
by Laurent
139:07 queued 124:29
created

Supplier::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
cc 1
nc 1
nop 11

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
namespace Domain\Model\Supplier;
6
7
use Domain\Model\Common\Entities\FamilyLog;
8
use Domain\Model\Common\VO\ContactAddress;
9
use Domain\Model\Common\VO\EmailField;
10
use Domain\Model\Common\VO\NameField;
11
use Domain\Model\Common\VO\PhoneField;
12
use Domain\Model\Contact;
13
14
class Supplier extends Contact
15
{
16
    /**
17
     * @var int Id of Supplier
18
     */
19
    private $supplierId;
20
21
    /**
22
     * @var string Logistics family
23
     */
24
    private $familyLog;
25
26
    /**
27
     * @var int Delivery delay
28
     */
29
    private $delayDeliv;
30
31
    /**
32
     * @var array Order days table
33
     */
34
    private $orderDays;
35
36
    /**
37
     * @var bool Active/Inactive
38
     */
39
    private $active;
40
41
    /**
42
     * @var string
43
     */
44
    private $slug;
45
46
    /**
47
     * Supplier constructor.
48
     *
49
     * @param NameField      $name
50
     * @param ContactAddress $address
51
     * @param PhoneField     $phone
52
     * @param PhoneField     $facsimile
53
     * @param EmailField     $email
54
     * @param string         $contact
55
     * @param PhoneField     $cellphone
56
     * @param FamilyLog      $familyLog
57
     * @param int            $delayDeliv
58
     * @param array          $orderDays
59
     * @param bool           $active
60
     */
61
    public function __construct(
62
        NameField $name,
63
        ContactAddress $address,
64
        PhoneField $phone,
65
        PhoneField $facsimile,
66
        EmailField $email,
67
        string $contact,
68
        PhoneField $cellphone,
69
        FamilyLog $familyLog,
70
        int $delayDeliv,
71
        array $orderDays,
72
        bool $active = true
73
    ) {
74
        parent::__construct(
75
            $name,
76
            $address,
77
            $phone->getValue(),
78
            $facsimile->getValue(),
79
            $email,
80
            $contact,
81
            $cellphone->getValue()
82
        );
83
        $this->familyLog = $familyLog->path();
84
        $this->delayDeliv = $delayDeliv;
85
        $this->orderDays = $orderDays;
86
        $this->slug = $name->slugify();
87
        $this->active = $active;
88
    }
89
90
    public static function create(
91
        NameField $name,
92
        string $address,
93
        string $zipCode,
94
        string $town,
95
        string $country,
96
        PhoneField $phone,
97
        PhoneField $facsimile,
98
        EmailField $email,
99
        string $contact,
100
        PhoneField $gsm,
101
        FamilyLog $familyLog,
102
        int $delayDeliv,
103
        array $orderDays,
104
        bool $active = true
105
    ): self {
106
        return new self(
107
            $name,
108
            ContactAddress::fromString($address, $zipCode, $town, $country),
109
            $phone,
110
            $facsimile,
111
            $email,
112
            $contact,
113
            $gsm,
114
            $familyLog,
115
            $delayDeliv,
116
            $orderDays,
117
            $active
118
        );
119
    }
120
121
    final public function renameSupplier(NameField $name): void
122
    {
123
        $this->name = $name->getValue();
124
        $this->slug = $name->slugify();
125
    }
126
127
    final public function name(): string
128
    {
129
        return $this->name;
130
    }
131
}
132