Passed
Push — main ( 0a00da...09db13 )
by
unknown
50s queued 13s
created

newCompanyChangeAddressRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 20
rs 9.9332
ccs 11
cts 11
cp 1
cc 1
nc 1
nop 8
crap 1

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 WMDE\Fundraising\AddressChangeContext\UseCases\ChangeAddress;
6
7
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressType;
8
9
class ChangeAddressRequest {
10 4
	private function __construct(
11
		public readonly AddressType $addressType,
12
		public readonly string $address,
13
		public readonly string $postcode,
14
		public readonly string $city,
15
		public readonly string $country,
16
		public readonly string $identifier,
17
		public readonly bool $donationReceipt,
18
		public readonly bool $isOptOutOnly,
19
		public readonly string $company = '',
20
		public readonly string $salutation = '',
21
		public readonly string $title = '',
22
		public readonly string $firstName = '',
23
		public readonly string $lastName = '',
24
	) {
25 4
	}
26
27 2
	public static function newPersonalChangeAddressRequest(
28
		string $salutation,
29
		string $title,
30
		string $firstName,
31
		string $lastName,
32
		string $address,
33
		string $postcode,
34
		string $city,
35
		string $country,
36
		string $identifier,
37
		bool $donationReceipt,
38
		bool $isOptOutOnly,
39
	): ChangeAddressRequest {
40 2
		return new self(
41 2
			addressType: AddressType::Person,
42 2
			address: trim( $address ),
43 2
			postcode: trim( $postcode ),
44 2
			city: trim( $city ),
45 2
			country: trim( $country ),
46 2
			identifier: trim( $identifier ),
47 2
			donationReceipt: $donationReceipt,
48 2
			isOptOutOnly: $isOptOutOnly,
49 2
			salutation: trim( $salutation ),
50 2
			title: trim( $title ),
51 2
			firstName: trim( $firstName ),
52 2
			lastName: trim( $lastName ),
53 2
		);
54
	}
55
56 2
	public static function newCompanyChangeAddressRequest(
57
		string $company,
58
		string $address,
59
		string $postcode,
60
		string $city,
61
		string $country,
62
		string $identifier,
63
		bool $donationReceipt,
64
		bool $isOptOutOnly,
65
	): ChangeAddressRequest {
66 2
		return new self(
67 2
			addressType: AddressType::Company,
68 2
			address: trim( $address ),
69 2
			postcode: trim( $postcode ),
70 2
			city: trim( $city ),
71 2
			country: trim( $country ),
72 2
			identifier: trim( $identifier ),
73 2
			donationReceipt: $donationReceipt,
74 2
			isOptOutOnly: $isOptOutOnly,
75 2
			company: trim( $company ),
76 2
		);
77
	}
78
79
	public function isPersonal(): bool {
80
		return $this->addressType === AddressType::Person;
81
	}
82
83
	public function isCompany(): bool {
84
		return $this->addressType === AddressType::Company;
85
	}
86
87
	public function isOptedOutOfDonationReceipt(): bool {
88
		return !$this->donationReceipt;
89
	}
90
91
	public function hasAddressChangeData(): bool {
92
		return !$this->isOptOutOnly;
93
	}
94
95
}
96