Complex classes like Donation 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 Donation, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | class Donation { |
||
32 | |||
33 | /** |
||
34 | * @since 2.0 |
||
35 | */ |
||
36 | public const STATUS_NEW = 'N'; // status for direct debit |
||
37 | public const STATUS_PROMISE = 'Z'; // status for bank transfer |
||
38 | public const STATUS_EXTERNAL_INCOMPLETE = 'X'; // status for external payments |
||
39 | public const STATUS_EXTERNAL_BOOKED = 'B'; // status for external payments |
||
40 | public const STATUS_MODERATION = 'P'; |
||
41 | public const STATUS_CANCELLED = 'D'; |
||
42 | |||
43 | /** |
||
44 | * @since 6.1 |
||
45 | * @deprecated since 6.1; This status is defined for historical reasons. It should not be used to define a |
||
46 | * donation's status anymore. |
||
47 | */ |
||
48 | public const STATUS_EXPORTED = 'E'; |
||
49 | |||
50 | /** |
||
51 | * @var integer |
||
52 | * |
||
53 | * @ORM\Column(name="id", type="integer") |
||
54 | * @ORM\Id |
||
55 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
56 | */ |
||
57 | private $id; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | * |
||
62 | * @ORM\Column(name="status", type="string", length=1, options={"default":"N", "fixed":true}, nullable=false) |
||
63 | */ |
||
64 | private $status = self::STATUS_NEW; |
||
65 | |||
66 | /** |
||
67 | * @var string |
||
68 | * |
||
69 | * @ORM\Column(name="name", type="string", length=250, nullable=true) |
||
70 | */ |
||
71 | private $donorFullName; |
||
72 | |||
73 | /** |
||
74 | * @var string |
||
75 | * |
||
76 | * @ORM\Column(name="ort", type="string", length=250, nullable=true) |
||
77 | */ |
||
78 | private $donorCity; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | * |
||
83 | * @ORM\Column(name="email", type="string", length=250, nullable=true) |
||
84 | */ |
||
85 | private $donorEmail; |
||
86 | |||
87 | /** |
||
88 | * @var boolean |
||
89 | * |
||
90 | * @ORM\Column(name="info", type="boolean", options={"default":0}, nullable=false) |
||
91 | */ |
||
92 | private $donorOptsIntoNewsletter = 0; |
||
93 | |||
94 | /** |
||
95 | * @var boolean |
||
96 | * |
||
97 | * @ORM\Column(name="bescheinigung", type="boolean", nullable=true) |
||
98 | */ |
||
99 | private $donationReceipt; |
||
100 | |||
101 | /** |
||
102 | * @var string |
||
103 | * |
||
104 | * @ORM\Column(name="eintrag", type="string", length=250, options={"default":""}, nullable=false) |
||
105 | */ |
||
106 | private $publicRecord = ''; |
||
107 | |||
108 | /** |
||
109 | * @var string |
||
110 | * |
||
111 | * @ORM\Column(name="betrag", type="string", length=250, nullable=true) |
||
112 | */ |
||
113 | private $amount; |
||
114 | |||
115 | /** |
||
116 | * @var integer |
||
117 | * |
||
118 | * @ORM\Column(name="periode", type="smallint", options={"default":0}, nullable=false) |
||
119 | */ |
||
120 | private $paymentIntervalInMonths = 0; |
||
121 | |||
122 | /** |
||
123 | * @var string |
||
124 | * |
||
125 | * @ORM\Column(name="zahlweise", type="string", length=3, options={"default":"BEZ", "fixed":true}, nullable=false) |
||
126 | */ |
||
127 | private $paymentType = 'BEZ'; |
||
128 | |||
129 | /** |
||
130 | * @var string |
||
131 | * |
||
132 | * @ORM\Column(name="kommentar", type="text", options={"default":""}, nullable=false) |
||
133 | */ |
||
134 | private $comment = ''; |
||
135 | |||
136 | /** |
||
137 | * @var string |
||
138 | * |
||
139 | * @ORM\Column(name="ueb_code", type="string", length=32, options={"default":""}, nullable=false) |
||
140 | */ |
||
141 | private $bankTransferCode = ''; |
||
142 | |||
143 | /** |
||
144 | * @var string |
||
145 | * |
||
146 | * @ORM\Column(name="data", type="text", nullable=true) |
||
147 | */ |
||
148 | private $data; |
||
149 | |||
150 | /** |
||
151 | * @var string |
||
152 | * |
||
153 | * @ORM\Column(name="source", type="string", length=250, nullable=true) |
||
154 | */ |
||
155 | private $source; |
||
156 | |||
157 | /** |
||
158 | * @var string |
||
159 | * |
||
160 | * @ORM\Column(name="remote_addr", type="string", length=250, options={"default":""}, nullable=false) |
||
161 | */ |
||
162 | private $remoteAddr = ''; |
||
163 | |||
164 | /** |
||
165 | * @var string |
||
166 | * |
||
167 | * @ORM\Column(name="hash", type="string", length=250, nullable=true) |
||
168 | */ |
||
169 | private $hash; |
||
170 | |||
171 | /** |
||
172 | * @var boolean |
||
173 | * |
||
174 | * @ORM\Column(name="is_public", type="boolean", options={"default":0}, nullable=false) |
||
175 | */ |
||
176 | private $isPublic = 0; |
||
177 | |||
178 | /** |
||
179 | * @var \DateTime |
||
180 | * |
||
181 | * @Gedmo\Timestampable(on="create") |
||
182 | * @ORM\Column(name="dt_new", type="datetime") |
||
183 | */ |
||
184 | private $creationTime; |
||
185 | |||
186 | /** |
||
187 | * @var \DateTime |
||
188 | * |
||
189 | * @ORM\Column(name="dt_del", type="datetime", nullable=true) |
||
190 | */ |
||
191 | private $deletionTime; |
||
192 | |||
193 | /** |
||
194 | * @var \DateTime |
||
195 | * |
||
196 | * @ORM\Column(name="dt_exp", type="datetime", nullable=true) |
||
197 | */ |
||
198 | private $dtExp; |
||
199 | |||
200 | /** |
||
201 | * @var \DateTime |
||
202 | * |
||
203 | * @ORM\Column(name="dt_gruen", type="datetime", nullable=true) |
||
204 | */ |
||
205 | private $dtGruen; |
||
206 | |||
207 | /** |
||
208 | * @var \DateTime |
||
209 | * |
||
210 | * @ORM\Column(name="dt_backup", type="datetime", nullable=true) |
||
211 | */ |
||
212 | private $dtBackup; |
||
213 | |||
214 | /** |
||
215 | * @ORM\OneToOne(targetEntity="WMDE\Fundraising\Entities\DonationPayment", cascade={"all"}, fetch="EAGER") |
||
216 | */ |
||
217 | private $payment; |
||
218 | |||
219 | /** |
||
220 | * @param string $donorFullName |
||
221 | * |
||
222 | * @return self |
||
223 | */ |
||
224 | public function setDonorFullName( $donorFullName ) { |
||
229 | |||
230 | /** |
||
231 | * @return string |
||
232 | */ |
||
233 | public function getDonorFullName() { |
||
236 | |||
237 | /** |
||
238 | * @param string $donorCity |
||
239 | * |
||
240 | * @return self |
||
241 | */ |
||
242 | public function setDonorCity( $donorCity ) { |
||
247 | |||
248 | /** |
||
249 | * @return string |
||
250 | */ |
||
251 | public function getDonorCity() { |
||
254 | |||
255 | /** |
||
256 | * @param string $donorEmail |
||
257 | * |
||
258 | * @return self |
||
259 | */ |
||
260 | public function setDonorEmail( $donorEmail ) { |
||
265 | |||
266 | /** |
||
267 | * @return string |
||
268 | */ |
||
269 | public function getDonorEmail() { |
||
272 | |||
273 | /** |
||
274 | * @param boolean $donorOptsIntoNewsletter |
||
275 | * |
||
276 | * @return self |
||
277 | */ |
||
278 | public function setDonorOptsIntoNewsletter( $donorOptsIntoNewsletter ) { |
||
283 | |||
284 | /** |
||
285 | * @return boolean |
||
286 | */ |
||
287 | public function getDonorOptsIntoNewsletter() { |
||
290 | |||
291 | /** |
||
292 | * Set donation receipt state |
||
293 | * |
||
294 | * @param boolean $donationReceipt |
||
295 | * @return self |
||
296 | */ |
||
297 | public function setDonationReceipt( $donationReceipt ) { |
||
302 | |||
303 | /** |
||
304 | * Get donation receipt state |
||
305 | * |
||
306 | * @return boolean |
||
307 | */ |
||
308 | public function getDonationReceipt() { |
||
311 | |||
312 | /** |
||
313 | * Set publicly displayed donation record |
||
314 | * |
||
315 | * @param string $publicRecord |
||
316 | * @return self |
||
317 | */ |
||
318 | public function setPublicRecord( $publicRecord ) { |
||
323 | |||
324 | /** |
||
325 | * Get publicly displayed donation record |
||
326 | * |
||
327 | * @return string |
||
328 | */ |
||
329 | public function getPublicRecord() { |
||
332 | |||
333 | /** |
||
334 | * @param string $amount |
||
335 | * @return self |
||
336 | */ |
||
337 | public function setAmount( $amount ) { |
||
342 | |||
343 | /** |
||
344 | * @return string |
||
345 | */ |
||
346 | public function getAmount() { |
||
349 | |||
350 | /** |
||
351 | * @param integer $paymentIntervalInMonths |
||
352 | * |
||
353 | * @return self |
||
354 | */ |
||
355 | public function setPaymentIntervalInMonths( $paymentIntervalInMonths ) { |
||
360 | |||
361 | /** |
||
362 | * @return integer |
||
363 | */ |
||
364 | public function getPaymentIntervalInMonths() { |
||
367 | |||
368 | /** |
||
369 | * Set payment type short code |
||
370 | * |
||
371 | * @param string $paymentType |
||
372 | * @return self |
||
373 | */ |
||
374 | public function setPaymentType( $paymentType ) { |
||
379 | |||
380 | /** |
||
381 | * Get payment type short code |
||
382 | * |
||
383 | * @return string |
||
384 | */ |
||
385 | public function getPaymentType() { |
||
388 | |||
389 | /** |
||
390 | * @param string $comment |
||
391 | * @return self |
||
392 | */ |
||
393 | public function setComment( $comment ) { |
||
398 | |||
399 | /** |
||
400 | * @return string |
||
401 | */ |
||
402 | public function getComment() { |
||
405 | |||
406 | /** |
||
407 | * Set bank transfer reference code |
||
408 | * |
||
409 | * @param string $bankTransferCode |
||
410 | * |
||
411 | * @return self |
||
412 | */ |
||
413 | public function setBankTransferCode( $bankTransferCode ) { |
||
418 | |||
419 | /** |
||
420 | * Get bank transfer reference code |
||
421 | * |
||
422 | * @return string |
||
423 | */ |
||
424 | public function getBankTransferCode() { |
||
427 | |||
428 | /** |
||
429 | * @param string $source |
||
430 | * @return self |
||
431 | */ |
||
432 | public function setSource( $source ) { |
||
437 | |||
438 | /** |
||
439 | * @return string |
||
440 | */ |
||
441 | public function getSource() { |
||
444 | |||
445 | /** |
||
446 | * @param string $remoteAddr |
||
447 | * @return self |
||
448 | */ |
||
449 | public function setRemoteAddr( $remoteAddr ) { |
||
454 | |||
455 | /** |
||
456 | * @return string |
||
457 | */ |
||
458 | public function getRemoteAddr() { |
||
461 | |||
462 | /** |
||
463 | * @param string $hash |
||
464 | * @return self |
||
465 | */ |
||
466 | public function setHash( $hash ) { |
||
471 | |||
472 | /** |
||
473 | * @return string |
||
474 | */ |
||
475 | public function getHash() { |
||
478 | |||
479 | /** |
||
480 | * Sets if the donations comment should be public or private. |
||
481 | * @param boolean $isPublic |
||
482 | * @return self |
||
483 | */ |
||
484 | public function setIsPublic( $isPublic ) { |
||
489 | |||
490 | /** |
||
491 | * Gets if the donations comment is public or private. |
||
492 | * @return boolean |
||
493 | */ |
||
494 | public function getIsPublic() { |
||
497 | |||
498 | /** |
||
499 | * @param \DateTime $creationTime |
||
500 | * |
||
501 | * @return self |
||
502 | */ |
||
503 | public function setCreationTime( $creationTime ) { |
||
508 | |||
509 | /** |
||
510 | * @return \DateTime |
||
511 | */ |
||
512 | public function getCreationTime() { |
||
515 | |||
516 | /** |
||
517 | * @param \DateTime|null $deletionTime |
||
518 | * |
||
519 | * @return self |
||
520 | */ |
||
521 | public function setDeletionTime( $deletionTime ) { |
||
526 | |||
527 | /** |
||
528 | * @return \DateTime|null |
||
529 | */ |
||
530 | public function getDeletionTime() { |
||
533 | |||
534 | /** |
||
535 | * @param \DateTime $dtExp |
||
536 | * @return self |
||
537 | */ |
||
538 | public function setDtExp( $dtExp ) { |
||
543 | |||
544 | /** |
||
545 | * @return \DateTime |
||
546 | */ |
||
547 | public function getDtExp() { |
||
550 | |||
551 | /** |
||
552 | * @param string $status |
||
553 | * @return self |
||
554 | */ |
||
555 | public function setStatus( $status ) { |
||
560 | |||
561 | /** |
||
562 | * @return string |
||
563 | */ |
||
564 | public function getStatus() { |
||
567 | |||
568 | /** |
||
569 | * @param \DateTime $dtGruen |
||
570 | * @return self |
||
571 | */ |
||
572 | public function setDtGruen( $dtGruen ) { |
||
577 | |||
578 | /** |
||
579 | * @return \DateTime |
||
580 | */ |
||
581 | public function getDtGruen() { |
||
584 | |||
585 | /** |
||
586 | * @param \DateTime $dtBackup |
||
587 | * @return self |
||
588 | */ |
||
589 | public function setDtBackup( $dtBackup ) { |
||
594 | |||
595 | /** |
||
596 | * @return \DateTime |
||
597 | */ |
||
598 | public function getDtBackup() { |
||
601 | |||
602 | /** |
||
603 | * @return integer|null |
||
604 | */ |
||
605 | 3 | public function getId() { |
|
608 | |||
609 | public function getPayment(): ?DonationPayment { |
||
612 | |||
613 | public function setPayment( DonationPayment $payment ) { |
||
616 | |||
617 | |||
618 | /** |
||
619 | * @since 2.0 |
||
620 | * |
||
621 | * @param integer|null $id |
||
622 | */ |
||
623 | 2 | public function setId( $id ) { |
|
626 | |||
627 | public function getUExpiry() { |
||
630 | |||
631 | public function uTokenIsExpired() { |
||
634 | |||
635 | public function validateToken( $tokenToCheck, $serverSecret ) { |
||
644 | |||
645 | public function getEntryType( $mode = null ) { |
||
667 | |||
668 | /** |
||
669 | * @deprecated since 2.0, use encodeAndSetData or setDataObject instead |
||
670 | * |
||
671 | * @param string $data Base 64 encoded, serialized PHP array |
||
672 | * @return self |
||
673 | */ |
||
674 | public function setData( $data ) { |
||
679 | |||
680 | /** |
||
681 | * @deprecated since 2.0, use @see getDecodedData or @see getDataObject instead |
||
682 | * |
||
683 | * @return string Base 64 encoded, serialized PHP array |
||
684 | */ |
||
685 | public function getData() { |
||
688 | |||
689 | /** |
||
690 | * NOTE: if possible, use @see getDataObject instead, as it provides a nicer API. |
||
691 | * |
||
692 | * @since 2.0 |
||
693 | * @return array |
||
694 | */ |
||
695 | 8 | public function getDecodedData() { |
|
704 | |||
705 | /** |
||
706 | * NOTE: if possible, use @see modifyDataObject instead, as it provides a nicer API. |
||
707 | * |
||
708 | * @since 2.0 |
||
709 | * @param array $data |
||
710 | */ |
||
711 | 6 | public function encodeAndSetData( array $data ) { |
|
714 | |||
715 | /** |
||
716 | * WARNING: updates made to the return value will not be reflected in the Donation state. |
||
717 | * Similarly, updates to the Donation state will not propagate to the returned object. |
||
718 | * To update the Donation state, explicitly call @see setDataObject. |
||
719 | * |
||
720 | * @since 2.0 |
||
721 | * @return DonationData |
||
722 | */ |
||
723 | 3 | public function getDataObject() { |
|
734 | |||
735 | /** |
||
736 | * @since 2.0 |
||
737 | * @param DonationData $data |
||
738 | */ |
||
739 | 4 | public function setDataObject( DonationData $data ) { |
|
757 | |||
758 | /** |
||
759 | * @since 2.0 |
||
760 | * @param callable $modificationFunction Takes a modifiable DonationData parameter |
||
761 | */ |
||
762 | 1 | public function modifyDataObject( callable $modificationFunction ) { |
|
767 | } |
||
768 |