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 |
||
| 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 { |
||
| 49 | |||
| 50 | public function setMembershipType( string $membershipType ): void { |
||
| 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 { |
||
| 61 | |||
| 62 | public function markApplicantAsCompany(): void { |
||
| 66 | |||
| 67 | public function getApplicantCompanyName(): string { |
||
| 70 | |||
| 71 | public function setApplicantCompanyName( string $applicantCompanyName ): void { |
||
| 74 | |||
| 75 | public function getApplicantSalutation(): string { |
||
| 78 | |||
| 79 | public function setApplicantSalutation( string $applicantSalutation ): void { |
||
| 83 | |||
| 84 | public function getApplicantTitle(): string { |
||
| 87 | |||
| 88 | public function setApplicantTitle( string $applicantTitle ): void { |
||
| 92 | |||
| 93 | public function getApplicantFirstName(): string { |
||
| 96 | |||
| 97 | public function setApplicantFirstName( string $applicantFirstName ): void { |
||
| 101 | |||
| 102 | public function getApplicantLastName(): string { |
||
| 105 | |||
| 106 | public function setApplicantLastName( string $applicantLastName ): void { |
||
| 110 | |||
| 111 | public function getApplicantStreetAddress(): string { |
||
| 114 | |||
| 115 | public function setApplicantStreetAddress( string $applicantStreetAddress ): void { |
||
| 119 | |||
| 120 | public function getApplicantPostalCode(): string { |
||
| 123 | |||
| 124 | public function setApplicantPostalCode( string $applicantPostalCode ): void { |
||
| 128 | |||
| 129 | public function getApplicantCity(): string { |
||
| 132 | |||
| 133 | public function setApplicantCity( string $applicantCity ): void { |
||
| 137 | |||
| 138 | public function getApplicantCountryCode(): string { |
||
| 141 | |||
| 142 | public function setApplicantCountryCode( string $applicantCountryCode ): void { |
||
| 146 | |||
| 147 | public function getApplicantEmailAddress(): string { |
||
| 150 | |||
| 151 | public function setApplicantEmailAddress( string $applicantEmailAddress ): void { |
||
| 155 | |||
| 156 | public function getApplicantPhoneNumber(): string { |
||
| 159 | |||
| 160 | public function setApplicantPhoneNumber( string $applicantPhoneNumber ): void { |
||
| 164 | |||
| 165 | public function getApplicantDateOfBirth(): string { |
||
| 168 | |||
| 169 | public function setApplicantDateOfBirth( string $applicantDateOfBirth ): void { |
||
| 173 | |||
| 174 | public function getPaymentIntervalInMonths(): int { |
||
| 177 | |||
| 178 | public function setPaymentIntervalInMonths( int $paymentIntervalInMonths ): void { |
||
| 182 | |||
| 183 | public function getPaymentAmountInEuros(): string { |
||
| 186 | |||
| 187 | public function setPaymentAmountInEuros( string $paymentAmount ): void { |
||
| 191 | |||
| 192 | public function getBankData(): ?BankData { |
||
| 195 | |||
| 196 | public function setBankData( BankData $bankData ): void { |
||
| 200 | |||
| 201 | public function getTrackingInfo(): MembershipApplicationTrackingInfo { |
||
| 204 | |||
| 205 | public function setTrackingInfo( MembershipApplicationTrackingInfo $trackingInfo ): void { |
||
| 209 | |||
| 210 | public function getPiwikTrackingString(): string { |
||
| 213 | |||
| 214 | public function setPiwikTrackingString( string $piwikTrackingString ): void { |
||
| 218 | |||
| 219 | public function getPaymentType(): string { |
||
| 222 | |||
| 223 | public function setPaymentType( string $paymentType ): void { |
||
| 227 | |||
| 228 | public function getOptsIntoDonationReceipt(): bool { |
||
| 231 | |||
| 232 | public function setOptsIntoDonationReceipt( bool $optIn ): void { |
||
| 236 | |||
| 237 | } |
||
| 238 |