Completed
Pull Request — master (#976)
by wiese
61:34
created

ApplyForMembershipRequest   B

Complexity

Total Complexity 42

Size/Duplication

Total Lines 223
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 42
lcom 1
cbo 1
dl 0
loc 223
rs 8.295
c 0
b 0
f 0

42 Methods

Rating   Name   Duplication   Size   Complexity  
A getMembershipType() 0 3 1
A setMembershipType() 0 4 1
A isCompanyApplication() 0 3 1
A markApplicantAsCompany() 0 4 1
A getApplicantCompanyName() 0 3 1
A setApplicantCompanyName() 0 3 1
A getApplicantSalutation() 0 3 1
A setApplicantSalutation() 0 4 1
A getApplicantTitle() 0 3 1
A setApplicantTitle() 0 4 1
A getApplicantFirstName() 0 3 1
A setApplicantFirstName() 0 4 1
A getApplicantLastName() 0 3 1
A setApplicantLastName() 0 4 1
A getApplicantStreetAddress() 0 3 1
A setApplicantStreetAddress() 0 4 1
A getApplicantPostalCode() 0 3 1
A setApplicantPostalCode() 0 4 1
A getApplicantCity() 0 3 1
A setApplicantCity() 0 4 1
A getApplicantCountryCode() 0 3 1
A setApplicantCountryCode() 0 4 1
A getApplicantEmailAddress() 0 3 1
A setApplicantEmailAddress() 0 4 1
A getApplicantPhoneNumber() 0 3 1
A setApplicantPhoneNumber() 0 4 1
A getApplicantDateOfBirth() 0 3 1
A setApplicantDateOfBirth() 0 4 1
A getPaymentIntervalInMonths() 0 3 1
A setPaymentIntervalInMonths() 0 4 1
A getPaymentAmountInEuros() 0 3 1
A setPaymentAmountInEuros() 0 4 1
A getBankData() 0 3 1
A setBankData() 0 4 1
A getTrackingInfo() 0 3 1
A setTrackingInfo() 0 4 1
A getPiwikTrackingString() 0 3 1
A setPiwikTrackingString() 0 4 1
A getPaymentType() 0 3 1
A setPaymentType() 0 4 1
A getOptsIntoDonationReceipt() 0 3 1
A setOptsIntoDonationReceipt() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like ApplyForMembershipRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ApplyForMembershipRequest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\MembershipContext\UseCases\ApplyForMembership;
6
7
use WMDE\Fundraising\Frontend\FreezableValueObject;
8
use WMDE\Fundraising\Frontend\MembershipContext\Tracking\MembershipApplicationTrackingInfo;
9
use WMDE\Fundraising\Frontend\PaymentContext\Domain\Model\BankData;
10
11
/**
12
 * @license GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class ApplyForMembershipRequest {
16
	use FreezableValueObject;
17
18
	private $membershipType;
19
20
	private $applicantIsCompany = false;
21
	private $applicantCompanyName;
22
	private $applicantSalutation;
23
	private $applicantTitle;
24
	private $applicantFirstName;
25
	private $applicantLastName;
26
27
	private $applicantStreetAddress;
28
	private $applicantPostalCode;
29
	private $applicantCity;
30
	private $applicantCountryCode;
31
32
	private $applicantEmailAddress;
33
	private $applicantPhoneNumber;
34
	private $applicantDateOfBirth;
35
36
	private $paymentType;
37
	private $paymentIntervalInMonths;
38
	private $paymentAmount;
39
	private $bankData;
40
41
	private $trackingInfo;
42
	private $piwikTrackingString;
43
44
	private $optsIntoDonationReceipt = true;
45
46
	public function getMembershipType(): string {
47
		return $this->membershipType;
48
	}
49
50
	public function setMembershipType( string $membershipType ): void {
51
		$this->assertIsWritable();
52
		$this->membershipType = $membershipType;
53
	}
54
55
	/**
56
	 * @return bool True when the applicant is a company, false when the applicant is a private person
57
	 */
58
	public function isCompanyApplication(): bool {
59
		return $this->applicantIsCompany;
60
	}
61
62
	public function markApplicantAsCompany(): void {
63
		$this->assertIsWritable();
64
		$this->applicantIsCompany = true;
65
	}
66
67
	public function getApplicantCompanyName(): string {
68
		return $this->applicantCompanyName;
69
	}
70
71
	public function setApplicantCompanyName( string $applicantCompanyName ): void {
72
		$this->applicantCompanyName = $applicantCompanyName;
73
	}
74
75
	public function getApplicantSalutation(): string {
76
		return $this->applicantSalutation;
77
	}
78
79
	public function setApplicantSalutation( string $applicantSalutation ): void {
80
		$this->assertIsWritable();
81
		$this->applicantSalutation = $applicantSalutation;
82
	}
83
84
	public function getApplicantTitle(): string {
85
		return $this->applicantTitle;
86
	}
87
88
	public function setApplicantTitle( string $applicantTitle ): void {
89
		$this->assertIsWritable();
90
		$this->applicantTitle = $applicantTitle;
91
	}
92
93
	public function getApplicantFirstName(): string {
94
		return $this->applicantFirstName;
95
	}
96
97
	public function setApplicantFirstName( string $applicantFirstName ): void {
98
		$this->assertIsWritable();
99
		$this->applicantFirstName = $applicantFirstName;
100
	}
101
102
	public function getApplicantLastName(): string {
103
		return $this->applicantLastName;
104
	}
105
106
	public function setApplicantLastName( string $applicantLastName ): void {
107
		$this->assertIsWritable();
108
		$this->applicantLastName = $applicantLastName;
109
	}
110
111
	public function getApplicantStreetAddress(): string {
112
		return $this->applicantStreetAddress;
113
	}
114
115
	public function setApplicantStreetAddress( string $applicantStreetAddress ): void {
116
		$this->assertIsWritable();
117
		$this->applicantStreetAddress = $applicantStreetAddress;
118
	}
119
120
	public function getApplicantPostalCode(): string {
121
		return $this->applicantPostalCode;
122
	}
123
124
	public function setApplicantPostalCode( string $applicantPostalCode ): void {
125
		$this->assertIsWritable();
126
		$this->applicantPostalCode = $applicantPostalCode;
127
	}
128
129
	public function getApplicantCity(): string {
130
		return $this->applicantCity;
131
	}
132
133
	public function setApplicantCity( string $applicantCity ): void {
134
		$this->assertIsWritable();
135
		$this->applicantCity = $applicantCity;
136
	}
137
138
	public function getApplicantCountryCode(): string {
139
		return $this->applicantCountryCode;
140
	}
141
142
	public function setApplicantCountryCode( string $applicantCountryCode ): void {
143
		$this->assertIsWritable();
144
		$this->applicantCountryCode = $applicantCountryCode;
145
	}
146
147
	public function getApplicantEmailAddress(): string {
148
		return $this->applicantEmailAddress;
149
	}
150
151
	public function setApplicantEmailAddress( string $applicantEmailAddress ): void {
152
		$this->assertIsWritable();
153
		$this->applicantEmailAddress = $applicantEmailAddress;
154
	}
155
156
	public function getApplicantPhoneNumber(): string {
157
		return $this->applicantPhoneNumber;
158
	}
159
160
	public function setApplicantPhoneNumber( string $applicantPhoneNumber ): void {
161
		$this->assertIsWritable();
162
		$this->applicantPhoneNumber = $applicantPhoneNumber;
163
	}
164
165
	public function getApplicantDateOfBirth(): string {
166
		return $this->applicantDateOfBirth;
167
	}
168
169
	public function setApplicantDateOfBirth( string $applicantDateOfBirth ): void {
170
		$this->assertIsWritable();
171
		$this->applicantDateOfBirth = $applicantDateOfBirth;
172
	}
173
174
	public function getPaymentIntervalInMonths(): int {
175
		return $this->paymentIntervalInMonths;
176
	}
177
178
	public function setPaymentIntervalInMonths( int $paymentIntervalInMonths ): void {
179
		$this->assertIsWritable();
180
		$this->paymentIntervalInMonths = $paymentIntervalInMonths;
181
	}
182
183
	public function getPaymentAmountInEuros(): string {
184
		return $this->paymentAmount;
185
	}
186
187
	public function setPaymentAmountInEuros( string $paymentAmount ): void {
188
		$this->assertIsWritable();
189
		$this->paymentAmount = $paymentAmount;
190
	}
191
192
	public function getBankData(): ?BankData {
193
		return $this->bankData;
194
	}
195
196
	public function setBankData( BankData $bankData ): void {
197
		$this->assertIsWritable();
198
		$this->bankData = $bankData;
199
	}
200
201
	public function getTrackingInfo(): MembershipApplicationTrackingInfo {
202
		return $this->trackingInfo;
203
	}
204
205
	public function setTrackingInfo( MembershipApplicationTrackingInfo $trackingInfo ): void {
206
		$this->assertIsWritable();
207
		$this->trackingInfo = $trackingInfo;
208
	}
209
210
	public function getPiwikTrackingString(): string {
211
		return $this->piwikTrackingString;
212
	}
213
214
	public function setPiwikTrackingString( string $piwikTrackingString ): void {
215
		$this->assertIsWritable();
216
		$this->piwikTrackingString = $piwikTrackingString;
217
	}
218
219
	public function getPaymentType(): string {
220
		return $this->paymentType;
221
	}
222
223
	public function setPaymentType( string $paymentType ): void {
224
		$this->assertIsWritable();
225
		$this->paymentType = $paymentType;
226
	}
227
228
	public function getOptsIntoDonationReceipt(): bool {
229
		return $this->optsIntoDonationReceipt;
230
	}
231
232
	public function setOptsIntoDonationReceipt( bool $optIn ): void {
233
		$this->assertIsWritable();
234
		$this->optsIntoDonationReceipt = $optIn;
235
	}
236
237
}
238