Passed
Pull Request — develop (#120)
by Laurent
05:37 queued 03:06
created

Contact::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 11
dl 0
loc 25
rs 9.8666
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 Core\Domain\Common\Model;
15
16
use Core\Domain\Common\Model\VO\ContactAddress;
17
use Core\Domain\Common\Model\VO\ContactUuid;
18
use Core\Domain\Common\Model\VO\EmailField;
19
use Core\Domain\Common\Model\VO\NameField;
20
use Core\Domain\Common\Model\VO\PhoneField;
21
22
abstract class Contact
23
{
24
    protected string $uuid;
25
    protected string $name;
26
    protected string $address;
27
    protected string $zipCode;
28
    protected string $town;
29
    protected string $country;
30
    protected string $phone;
31
    protected string $facsimile;
32
    protected string $email;
33
    protected string $contact;
34
    protected string $cellphone;
35
    protected string $slug;
36
37
    public function __construct(
38
        ContactUuid $uuid,
39
        NameField $name,
40
        string $address,
41
        string $zipCode,
42
        string $town,
43
        string $country,
44
        PhoneField $phone,
45
        PhoneField $facsimile,
46
        EmailField $email,
47
        string $contact,
48
        PhoneField $cellphone
49
    ) {
50
        $this->uuid = $uuid->toString();
51
        $this->name = $name->getValue();
52
        $this->slug = $name->slugify();
53
        $this->address = $address;
54
        $this->zipCode = $zipCode;
55
        $this->town = $town;
56
        $this->country = $country;
57
        $this->phone = $phone->getValue();
58
        $this->facsimile = $facsimile->getValue();
59
        $this->email = $email->getValue();
60
        $this->contact = $contact;
61
        $this->cellphone = $cellphone->getValue();
62
    }
63
64
    final public function uuid(): string
65
    {
66
        return $this->uuid;
67
    }
68
69
    final public function name(): string
70
    {
71
        return $this->name;
72
    }
73
74
    final public function fullAddress(): string
75
    {
76
        return ContactAddress::fromArray([$this->address, $this->zipCode, $this->town, $this->country])->getValue();
77
    }
78
79
    final public function rewriteAddress(array $addressData): void
80
    {
81
        $address = ContactAddress::fromArray($addressData);
82
        $this->address = $address->address();
83
        $this->zipCode = $address->zipCode();
84
        $this->town = $address->town();
85
        $this->country = $address->country();
86
    }
87
88
    final public function phone(): string
89
    {
90
        return $this->phone;
91
    }
92
93
    final public function changePhoneNumber(PhoneField $phone): void
94
    {
95
        $this->phone = $phone->getValue();
96
    }
97
98
    final public function facsimile(): string
99
    {
100
        return $this->facsimile;
101
    }
102
103
    final public function changeFacsimileNumber(PhoneField $facsimile): void
104
    {
105
        $this->facsimile = $facsimile->getValue();
106
    }
107
108
    final public function email(): string
109
    {
110
        return $this->email;
111
    }
112
113
    final public function rewriteEmail(EmailField $email): void
114
    {
115
        $this->email = $email->getValue();
116
    }
117
118
    final public function contact(): string
119
    {
120
        return $this->contact;
121
    }
122
123
    final public function renameContact(string $contact): void
124
    {
125
        $this->contact = $contact;
126
    }
127
128
    final public function cellphone(): string
129
    {
130
        return $this->cellphone;
131
    }
132
133
    final public function changeCellphoneNumber(PhoneField $cellphone): void
134
    {
135
        $this->cellphone = $cellphone->getValue();
136
    }
137
138
    final public function slug(): string
139
    {
140
        return $this->slug;
141
    }
142
143
    final public function address(): string
144
    {
145
        return $this->address;
146
    }
147
148
    final public function zipCode(): string
149
    {
150
        return $this->zipCode;
151
    }
152
153
    final public function town(): string
154
    {
155
        return $this->town;
156
    }
157
158
    final public function country(): string
159
    {
160
        return $this->country;
161
    }
162
}
163