Passed
Push — develop ( 229fa6...7d2e81 )
by Laurent
08:00 queued 04:20
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
c 0
b 0
f 0
nc 1
nop 11
dl 0
loc 25
rs 9.8666

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