Passed
Push — master ( e21ea4...5cdd3c )
by Laurens
01:37
created

Customer::new()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 41
ccs 0
cts 21
cp 0
rs 9.28
c 0
b 0
f 0
cc 1
nc 1
nop 18
crap 2

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 LauLamanApps\eCurring\Resource;
6
7
use DateTimeImmutable;
8
use LauLamanApps\eCurring\Resource\Customer\Gender;
9
use LauLamanApps\eCurring\Resource\Customer\VerificationMethod;
10
use LauLamanApps\eCurring\Resource\Transaction\PaymentMethod;
11
12
final class Customer implements CustomerInterface
13
{
14
    /**
15
     * @var int
16
     */
17
    private $id;
18
19
    /**
20
     * @var Gender|null
21
     *
22
     * The gender of the customer.
23
     * Used to determine the salutation in communication with the customer. Possible values: m / f
24
     */
25
    private $gender;
26
27
    /**
28
     * @var string
29
     *
30
     * The first name of the customer
31
     */
32
    private $firstName;
33
34
    /**
35
     * @var string|null
36
     *
37
     * The middle name of the customer
38
     */
39
    private $middleName;
40
41
    /**
42
     * @var string
43
     *
44
     * The last name of the customer
45
     */
46
    private $lastName;
47
48
    /**
49
     * @var string|null
50
     *
51
     * The name of the company of the customer
52
     */
53
    private $companyName;
54
55
    /**
56
     * @var string|null
57
     *
58
     * The vat number of the company of the customer
59
     */
60
    private $vatNumber;
61
62
    /**
63
     * @var PaymentMethod
64
     *
65
     * The payment type used to collect the funds from the customer.
66
     */
67
    private $paymentType;
68
69
    /**
70
     * @var VerificationMethod|null
71
     *
72
     * The method used used by the customer to validate their bankaccount or creditcard.
73
     * Empty when IBAN is manually entered.
74
     */
75
    private $bankVerificationMethod;
76
77
    /**
78
     * @var string
79
     *
80
     * The name of the holder of the bank account or creditcard.
81
     * Replaces the deprecated bankHolder.
82
     */
83
    private $cardHolder;
84
85
    /**
86
     * @var string
87
     *
88
     * The last 4 digits of the bank account or creditcard of the client.
89
     */
90
    private $cardNumber;
91
92
    /**
93
     * @var string|null
94
     *
95
     * The postalcode of the address of the customer
96
     */
97
    private $postalcode;
98
99
    /**
100
     * @var string|null
101
     *
102
     * The house number of the address of the customer
103
     */
104
    private $houseNumber;
105
106
    /**
107
     * @var string|null
108
     *
109
     * The house number addition of the address of the customer
110
     */
111
    private $houseNumberAdd;
112
113
    /**
114
     * @var string|null
115
     *
116
     * The street of the address of the customer
117
     */
118
    private $street;
119
120
    /**
121
     * @var string|null
122
     *
123
     * The city of the address of the customer
124
     */
125
    private $city;
126
127
    /**
128
     * @var string|null
129
     *
130
     * The 2 letter ISO code of the country of residence of the customer
131
     */
132
    private $countryCode;
133
134
    /**
135
     * @var string|null
136
     *
137
     * The preferred communication language of the customer.
138
     * Any notifications sent to the customer will be in this language.
139
     * Possible values: nl / en.
140
     */
141
    private $language;
142
143
    /**
144
     * @var string
145
     *
146
     * The email address of the customer
147
     */
148
    private $email;
149
150
    /**
151
     * @var string|null
152
     *
153
     * The telephone number of the customer
154
     */
155
    private $telephone;
156
157
    /**
158
     * @var SubscriptionInterface[]
159
     *
160
     * The subscriptions of the customers
161
     */
162
    private $subscriptions;
163
164
    /**
165
     * @var DateTimeImmutable
166
     *
167
     * The date on which the customer was created
168
     */
169
    private $createdAt;
170
171
    /**
172
     * @var DateTimeImmutable
173
     *
174
     * The date on which the customer was last updated
175
     */
176
    private $updatedAt;
177
178 1
    private function __construct()
179
    {
180 1
    }
181
182
    public static function new(
183
        string $firstName,
184
        string $lastName,
185
        PaymentMethod $paymentType,
186
        string $cardHolder,
187
        string $cardNumber,
188
        string $email,
189
        ?Gender $gender = null,
190
        ?string $middleName = null,
191
        ?string $companyName = null,
192
        ?string $vatNumber = null,
193
        ?string $postalcode = null,
194
        ?string $houseNumber = null,
195
        ?string $houseNumberAdd = null,
196
        ?string $street = null,
197
        ?string $city = null,
198
        ?string $countryCode = null,
199
        ?string $language = null,
200
        ?string $telephone = null
201
    ): self {
202
        $self = new self();
203
        $self->gender = $gender;
204
        $self->firstName = $firstName;
205
        $self->lastName = $lastName;
206
        $self->paymentType = $paymentType;
207
        $self->cardHolder = $cardHolder;
208
        $self->cardNumber = $cardNumber;
209
        $self->email = $email;
210
        $self->middleName = $middleName;
211
        $self->companyName = $companyName;
212
        $self->vatNumber = $vatNumber;
213
        $self->postalcode = $postalcode;
214
        $self->houseNumber = $houseNumber;
215
        $self->houseNumberAdd = $houseNumberAdd;
216
        $self->street = $street;
217
        $self->city = $city;
218
        $self->countryCode = $countryCode;
219
        $self->language = $language;
220
        $self->telephone = $telephone;
221
222
        return $self;
223
    }
224
225 1
    public static function fromData(
226
        int $id,
227
        string $firstName,
228
        string $lastName,
229
        PaymentMethod $paymentType,
230
        string $cardHolder,
231
        string $cardNumber,
232
        string $email,
233
        DateTimeImmutable $createdAt,
234
        DateTimeImmutable $updatedAt,
235
        ?Gender $gender = null,
236
        ?string $middleName = null,
237
        ?string $companyName = null,
238
        ?string $vatNumber = null,
239
        ?string $postalcode = null,
240
        ?string $houseNumber = null,
241
        ?string $houseNumberAdd = null,
242
        ?string $street = null,
243
        ?string $city = null,
244
        ?string $countryCode = null,
245
        ?string $language = null,
246
        ?string $telephone = null,
247
        ?VerificationMethod $bankVerificationMethod = null,
248
        ?SubscriptionInterface ...$subscriptions
249
    ): self {
250 1
        $self = new self();
251 1
        $self->id = $id;
252 1
        $self->firstName = $firstName;
253 1
        $self->lastName = $lastName;
254 1
        $self->paymentType = $paymentType;
255 1
        $self->cardHolder = $cardHolder;
256 1
        $self->cardNumber = $cardNumber;
257 1
        $self->email = $email;
258 1
        $self->createdAt = $createdAt;
259 1
        $self->updatedAt = $updatedAt;
260 1
        $self->gender = $gender;
261 1
        $self->companyName = $companyName;
262 1
        $self->vatNumber = $vatNumber;
263 1
        $self->postalcode = $postalcode;
264 1
        $self->houseNumber = $houseNumber;
265 1
        $self->houseNumberAdd = $houseNumberAdd;
266 1
        $self->street = $street;
267 1
        $self->city = $city;
268 1
        $self->countryCode = $countryCode;
269 1
        $self->language = $language;
270 1
        $self->telephone = $telephone;
271 1
        $self->middleName = $middleName;
272 1
        $self->bankVerificationMethod = $bankVerificationMethod;
273 1
        $self->subscriptions = $subscriptions;
274
275 1
        return $self;
276
    }
277
278
279 1
    public function getId(): int
280
    {
281 1
        return $this->id;
282
    }
283
284 1
    public function getGender(): ?Gender
285
    {
286 1
        return $this->gender;
287
    }
288
289 1
    public function getFirstName(): string
290
    {
291 1
        return $this->firstName;
292
    }
293
294 1
    public function getMiddleName(): ?string
295
    {
296 1
        return $this->middleName;
297
    }
298
299 1
    public function getLastName(): string
300
    {
301 1
        return $this->lastName;
302
    }
303
304 1
    public function getCompanyName(): ?string
305
    {
306 1
        return $this->companyName;
307
    }
308
309 1
    public function getVatNumber(): ?string
310
    {
311 1
        return $this->vatNumber;
312
    }
313
314 1
    public function getPaymentType(): PaymentMethod
315
    {
316 1
        return $this->paymentType;
317
    }
318
319 1
    public function getBankVerificationMethod(): ?VerificationMethod
320
    {
321 1
        return $this->bankVerificationMethod;
322
    }
323
324 1
    public function getCardHolder(): string
325
    {
326 1
        return $this->cardHolder;
327
    }
328
329 1
    public function getCardNumber(): string
330
    {
331 1
        return $this->cardNumber;
332
    }
333
334 1
    public function getPostalcode(): ?string
335
    {
336 1
        return $this->postalcode;
337
    }
338
339 1
    public function getHouseNumber(): ?string
340
    {
341 1
        return $this->houseNumber;
342
    }
343
344 1
    public function getHouseNumberAdd(): ?string
345
    {
346 1
        return $this->houseNumberAdd;
347
    }
348
349 1
    public function getStreet(): ?string
350
    {
351 1
        return $this->street;
352
    }
353
354 1
    public function getCity(): ?string
355
    {
356 1
        return $this->city;
357
    }
358
359 1
    public function getCountryCode(): ?string
360
    {
361 1
        return $this->countryCode;
362
    }
363
364 1
    public function getLanguage(): ?string
365
    {
366 1
        return $this->language;
367
    }
368
369 1
    public function getEmail(): string
370
    {
371 1
        return $this->email;
372
    }
373
374 1
    public function getTelephone(): ?string
375
    {
376 1
        return $this->telephone;
377
    }
378
379
    /**
380
     * @return SubscriptionInterface[]
381
     */
382 1
    public function getSubscriptions(): array
383
    {
384 1
        return $this->subscriptions;
385
    }
386
387
    public function getCreatedAt(): DateTimeImmutable
388
    {
389
        return $this->createdAt;
390
    }
391
392
    public function getUpdatedAt(): DateTimeImmutable
393
    {
394
        return $this->updatedAt;
395
    }
396
}
397