Test Failed
Push — master ( 286c96...e21ea4 )
by Laurens
01:29
created

Customer::fromData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 51
rs 9.52
c 0
b 0
f 0
ccs 0
cts 21
cp 0
cc 1
nc 1
nop 23
crap 2

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 Subscription[]
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
    private function __construct()
179
    {
180
    }
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
    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
        $self = new self();
251
        $self->id = $id;
252
        $self->firstName = $firstName;
253
        $self->lastName = $lastName;
254
        $self->paymentType = $paymentType;
255
        $self->cardHolder = $cardHolder;
256
        $self->cardNumber = $cardNumber;
257
        $self->email = $email;
258
        $self->createdAt = $createdAt;
259
        $self->updatedAt = $updatedAt;
260
        $self->gender = $gender;
261
        $self->companyName = $companyName;
262
        $self->vatNumber = $vatNumber;
263
        $self->postalcode = $postalcode;
264
        $self->houseNumber = $houseNumber;
265
        $self->houseNumberAdd = $houseNumberAdd;
266
        $self->street = $street;
267
        $self->city = $city;
268
        $self->countryCode = $countryCode;
269
        $self->language = $language;
270
        $self->telephone = $telephone;
271
        $self->middleName = $middleName;
272
        $self->bankVerificationMethod = $bankVerificationMethod;
273
        $self->subscriptions = $subscriptions;
0 ignored issues
show
Documentation Bug introduced by
$subscriptions is of type array<integer,null|LauLa...\SubscriptionInterface>, but the property $subscriptions was declared to be of type LauLamanApps\eCurring\Resource\Subscription[]. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
274
275
        return $self;
276
    }
277
278
279
    public function getId(): int
280
    {
281
        return $this->id;
282
    }
283
284
    public function getGender(): ?Gender
285
    {
286
        return $this->gender;
287
    }
288
289
    public function getFirstName(): string
290
    {
291
        return $this->firstName;
292
    }
293
294
    public function getMiddleName(): ?string
295
    {
296
        return $this->middleName;
297
    }
298
299
    public function getLastName(): string
300
    {
301
        return $this->lastName;
302
    }
303
304
    public function getCompanyName(): ?string
305
    {
306
        return $this->companyName;
307
    }
308
309
    public function getVatNumber(): ?string
310
    {
311
        return $this->vatNumber;
312
    }
313
314
    public function getPaymentType(): PaymentMethod
315
    {
316
        return $this->paymentType;
317
    }
318
319
    public function getBankVerificationMethod(): ?VerificationMethod
320
    {
321
        return $this->bankVerificationMethod;
322
    }
323
324
    public function getCardHolder(): string
325
    {
326
        return $this->cardHolder;
327
    }
328
329
    public function getCardNumber(): string
330
    {
331
        return $this->cardNumber;
332
    }
333
334
    public function getPostalcode(): ?string
335
    {
336
        return $this->postalcode;
337
    }
338
339
    public function getHouseNumber(): ?string
340
    {
341
        return $this->houseNumber;
342
    }
343
344
    public function getHouseNumberAdd(): ?string
345
    {
346
        return $this->houseNumberAdd;
347
    }
348
349
    public function getStreet(): ?string
350
    {
351
        return $this->street;
352
    }
353
354
    public function getCity(): ?string
355
    {
356
        return $this->city;
357
    }
358
359
    public function getCountryCode(): ?string
360
    {
361
        return $this->countryCode;
362
    }
363
364
    public function getLanguage(): ?string
365
    {
366
        return $this->language;
367
    }
368
369
    public function getEmail(): string
370
    {
371
        return $this->email;
372
    }
373
374
    public function getTelephone(): ?string
375
    {
376
        return $this->telephone;
377
    }
378
379
    /**
380
     * @return SubscriptionInterface[]
381
     */
382
    public function getSubscriptions(): array
383
    {
384
        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