Complex classes like AddDonationRequest 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 AddDonationRequest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class AddDonationRequest { |
||
| 17 | |||
| 18 | private $donorType; |
||
| 19 | private $donorFirstName; |
||
| 20 | private $donorLastName; |
||
| 21 | private $donorSalutation; |
||
| 22 | private $donorTitle; |
||
| 23 | private $donorCompany; |
||
| 24 | private $donorStreetAddress; |
||
| 25 | private $donorPostalCode; |
||
| 26 | private $donorCity; |
||
| 27 | private $donorCountryCode; |
||
| 28 | private $donorEmailAddress; |
||
| 29 | |||
| 30 | private $optIn = ''; |
||
| 31 | |||
| 32 | # donation |
||
| 33 | private $amount; |
||
| 34 | private $paymentType = ''; |
||
| 35 | private $interval = 0; |
||
| 36 | |||
| 37 | # direct debit related |
||
| 38 | private $bankData; |
||
| 39 | |||
| 40 | # tracking |
||
| 41 | private $tracking = ''; |
||
| 42 | private $source = ''; # TODO: generated from referer |
||
| 43 | private $totalImpressionCount = 0; |
||
| 44 | private $singleBannerImpressionCount = 0; |
||
| 45 | private $color = ''; # TODO: drop this? |
||
| 46 | private $skin = ''; # TODO: drop this? |
||
| 47 | private $layout = ''; # TODO: drop this? |
||
| 48 | |||
| 49 | public function getOptIn(): string { |
||
| 52 | |||
| 53 | public function setOptIn( string $optIn ) { |
||
| 56 | |||
| 57 | public function getAmount(): Euro { |
||
| 60 | |||
| 61 | public function setAmount( Euro $amount ) { |
||
| 64 | |||
| 65 | public function getPaymentType(): string { |
||
| 68 | |||
| 69 | public function setPaymentType( string $paymentType ) { |
||
| 72 | |||
| 73 | public function getInterval(): int { |
||
| 76 | |||
| 77 | public function setInterval( int $interval ) { |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return BankData|null |
||
| 83 | */ |
||
| 84 | public function getBankData() { |
||
| 87 | |||
| 88 | public function setBankData( BankData $bankData ) { |
||
| 91 | |||
| 92 | public function getTracking(): string { |
||
| 95 | |||
| 96 | public function setTracking( string $tracking ) { |
||
| 99 | |||
| 100 | public function getSource(): string { |
||
| 103 | |||
| 104 | public function setSource( string $source ) { |
||
| 107 | |||
| 108 | public function getTotalImpressionCount(): int { |
||
| 111 | |||
| 112 | public function setTotalImpressionCount( int $totalImpressionCount ) { |
||
| 115 | |||
| 116 | public function getSingleBannerImpressionCount(): int { |
||
| 119 | |||
| 120 | public function setSingleBannerImpressionCount( int $singleBannerImpressionCount ) { |
||
| 123 | |||
| 124 | public function getColor(): string { |
||
| 127 | |||
| 128 | public function setColor( string $color ) { |
||
| 131 | |||
| 132 | public function getSkin(): string { |
||
| 135 | |||
| 136 | public function setSkin( string $skin ) { |
||
| 139 | |||
| 140 | public function getLayout(): string { |
||
| 143 | |||
| 144 | public function setLayout( string $layout ) { |
||
| 147 | |||
| 148 | public function getDonorType(): string { |
||
| 151 | |||
| 152 | public function setDonorType( string $donorType ) { |
||
| 155 | |||
| 156 | public function getDonorFirstName(): string { |
||
| 159 | |||
| 160 | public function setDonorFirstName( string $donorFirstName ) { |
||
| 163 | |||
| 164 | public function getDonorLastName(): string { |
||
| 167 | |||
| 168 | public function setDonorLastName( string $donorLastName ) { |
||
| 171 | |||
| 172 | public function getDonorSalutation(): string { |
||
| 175 | |||
| 176 | public function setDonorSalutation( string $donorSalutation ) { |
||
| 179 | |||
| 180 | public function getDonorTitle(): string { |
||
| 183 | |||
| 184 | public function setDonorTitle( string $donorTitle ) { |
||
| 187 | |||
| 188 | public function getDonorCompany(): string { |
||
| 191 | |||
| 192 | public function setDonorCompany( string $donorCompany ) { |
||
| 195 | |||
| 196 | public function getDonorStreetAddress(): string { |
||
| 199 | |||
| 200 | public function setDonorStreetAddress( string $donorStreetAddress ) { |
||
| 203 | |||
| 204 | public function getDonorPostalCode(): string { |
||
| 207 | |||
| 208 | public function setDonorPostalCode( string $donorPostalCode ) { |
||
| 211 | |||
| 212 | public function getDonorCity(): string { |
||
| 215 | |||
| 216 | public function setDonorCity( string $donorCity ) { |
||
| 219 | |||
| 220 | public function getDonorCountryCode(): string { |
||
| 223 | |||
| 224 | public function setDonorCountryCode( string $donorCountryCode ) { |
||
| 227 | |||
| 228 | public function getDonorEmailAddress(): string { |
||
| 231 | |||
| 232 | public function setDonorEmailAddress( string $donorEmailAddress ) { |
||
| 235 | |||
| 236 | public static function getPreferredValue( array $values ) { |
||
| 245 | |||
| 246 | public static function concatTrackingFromVarCouple( string $campaign, string $keyword ): string { |
||
| 253 | |||
| 254 | public function donorIsAnonymous(): bool { |
||
| 257 | |||
| 258 | public function donorIsCompany(): bool { |
||
| 261 | } |