Complex classes like MembershipApplication 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 MembershipApplication, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class MembershipApplication { |
||
15 | |||
16 | /** |
||
17 | * @var integer |
||
18 | * |
||
19 | * @ORM\Column(name="donation_id", type="integer", nullable=true) |
||
20 | */ |
||
21 | private $donationId; |
||
22 | |||
23 | /** |
||
24 | * @var \DateTime |
||
25 | * |
||
26 | * @Gedmo\Timestampable(on="create") |
||
27 | * @ORM\Column(name="timestamp", type="datetime") |
||
28 | */ |
||
29 | private $timestamp; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | * |
||
34 | * @ORM\Column(name="anrede", type="string", length=16, nullable=true) |
||
35 | */ |
||
36 | private $salutation; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | * |
||
41 | * @ORM\Column(name="firma", type="string", length=100, nullable=true) |
||
42 | */ |
||
43 | private $company; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | * |
||
48 | * @ORM\Column(name="titel", type="string", length=16, nullable=true) |
||
49 | */ |
||
50 | private $title; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | * |
||
55 | * @ORM\Column(name="name", type="string", length=250, options={"default":""}, nullable=false) |
||
56 | */ |
||
57 | private $name = ''; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | * |
||
62 | * @ORM\Column(name="vorname", type="string", length=50, options={"default":""}, nullable=false) |
||
63 | */ |
||
64 | private $firstName = ''; |
||
65 | |||
66 | /** |
||
67 | * @var string |
||
68 | * |
||
69 | * @ORM\Column(name="nachname", type="string", length=50, options={"default":""}, nullable=false) |
||
70 | */ |
||
71 | private $lastName = ''; |
||
72 | |||
73 | /** |
||
74 | * @var string |
||
75 | * |
||
76 | * @ORM\Column(name="strasse", type="string", length=100, nullable=true) |
||
77 | */ |
||
78 | private $address; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | * |
||
83 | * @ORM\Column(name="plz", type="string", length=8, nullable=true) |
||
84 | */ |
||
85 | private $postcode; |
||
86 | |||
87 | /** |
||
88 | * @var string |
||
89 | * |
||
90 | * @ORM\Column(name="ort", type="string", length=100, nullable=true) |
||
91 | */ |
||
92 | private $city; |
||
93 | |||
94 | /** |
||
95 | * @var string |
||
96 | * |
||
97 | * @ORM\Column(name="email", type="string", length=250, options={"default":""}, nullable=false) |
||
98 | */ |
||
99 | private $email = ''; |
||
100 | |||
101 | /** |
||
102 | * @var string |
||
103 | * |
||
104 | * @ORM\Column(name="phone", type="string", length=30, options={"default":""}, nullable=false) |
||
105 | */ |
||
106 | private $phone = ''; |
||
107 | |||
108 | /** |
||
109 | * Date of birth |
||
110 | * |
||
111 | * @var \DateTime |
||
112 | * |
||
113 | * @ORM\Column(name="dob", type="date", nullable=true) |
||
114 | */ |
||
115 | private $dob; |
||
116 | |||
117 | /** |
||
118 | * @var string |
||
119 | * |
||
120 | * @ORM\Column(name="wikimedium_shipping", type="string", options={"default":""}, nullable=false) |
||
121 | */ |
||
122 | private $wikimediumShipping = 'none'; |
||
123 | |||
124 | /** |
||
125 | * @var string |
||
126 | * |
||
127 | * @ORM\Column(name="membership_type", type="string", options={"default":"sustaining"}, nullable=false) |
||
128 | */ |
||
129 | private $membershipType = 'sustaining'; |
||
130 | |||
131 | /** |
||
132 | * @var integer |
||
133 | * |
||
134 | * @ORM\Column(name="membership_fee", type="integer", options={"default":0}, nullable=false) |
||
135 | */ |
||
136 | private $membershipFee = 0; |
||
137 | |||
138 | /** |
||
139 | * @var integer |
||
140 | * |
||
141 | * @ORM\Column(name="membership_fee_interval", type="smallint", options={"default":12}, nullable=true) |
||
142 | */ |
||
143 | |||
144 | private $membershipFeeInterval = 12; |
||
145 | |||
146 | /** |
||
147 | * @var string |
||
148 | * |
||
149 | * @ORM\Column(name="account_number", type="string", length=16, options={"default":""}, nullable=false) |
||
150 | */ |
||
151 | private $accountNumber = ''; |
||
152 | |||
153 | /** |
||
154 | * @var string |
||
155 | * |
||
156 | * @ORM\Column(name="bank_name", type="string", length=50, options={"default":""}, nullable=false) |
||
157 | */ |
||
158 | private $bankName = ''; |
||
159 | |||
160 | /** |
||
161 | * @var string |
||
162 | * |
||
163 | * @ORM\Column(name="bank_code", type="string", length=16, options={"default":""}, nullable=false) |
||
164 | */ |
||
165 | private $bankCode = ''; |
||
166 | |||
167 | /** |
||
168 | * @var string |
||
169 | * |
||
170 | * @ORM\Column(name="iban", type="string", length=32, options={"default":""}, nullable=true) |
||
171 | */ |
||
172 | private $iban = ''; |
||
173 | |||
174 | /** |
||
175 | * @var string |
||
176 | * |
||
177 | * @ORM\Column(name="bic", type="string", length=32, options={"default":""}, nullable=true) |
||
178 | */ |
||
179 | private $bic = ''; |
||
180 | |||
181 | /** |
||
182 | * @var string |
||
183 | * |
||
184 | * @ORM\Column(name="account_holder", type="string", length=50, options={"default":""}, nullable=false) |
||
185 | */ |
||
186 | private $accountHolder = ''; |
||
187 | |||
188 | /** |
||
189 | * @var string |
||
190 | * |
||
191 | * @ORM\Column(name="comment", type="text", options={"default":""}, nullable=false) |
||
192 | */ |
||
193 | private $comment = ''; |
||
194 | |||
195 | /** |
||
196 | * @var \DateTime |
||
197 | * |
||
198 | * @ORM\Column(name="export", type="datetime", nullable=true) |
||
199 | */ |
||
200 | private $export; |
||
201 | |||
202 | /** |
||
203 | * @var \DateTime |
||
204 | * |
||
205 | * @ORM\Column(name="backup", type="datetime", nullable=true) |
||
206 | */ |
||
207 | private $backup; |
||
208 | |||
209 | /** |
||
210 | * @var boolean |
||
211 | * |
||
212 | * @ORM\Column(name="wikilogin", type="boolean", options={"default":0}, nullable=false) |
||
213 | */ |
||
214 | private $wikilogin = 0; |
||
215 | |||
216 | /** |
||
217 | * @var string |
||
218 | * |
||
219 | * @ORM\Column(name="tracking", type="string", length=50, nullable=true) |
||
220 | */ |
||
221 | private $tracking; |
||
222 | |||
223 | /** |
||
224 | * @var integer |
||
225 | * |
||
226 | * @ORM\Column(name="status", type="smallint", options={"default":0}, nullable=true) |
||
227 | */ |
||
228 | private $status = 0; |
||
229 | |||
230 | /** |
||
231 | * @var string |
||
232 | * |
||
233 | * @ORM\Column(name="country", type="string", length=8, options={"default":""}, nullable=true) |
||
234 | */ |
||
235 | private $country = ''; |
||
236 | |||
237 | /** |
||
238 | * @var string |
||
239 | * |
||
240 | * @ORM\Column(name="data", type="text", nullable=true) |
||
241 | */ |
||
242 | private $data; |
||
243 | |||
244 | /** |
||
245 | * @var integer |
||
246 | * |
||
247 | * @ORM\Column(name="id", type="integer") |
||
248 | * @ORM\Id |
||
249 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
250 | */ |
||
251 | private $id; |
||
252 | |||
253 | const STATUS_CONFIRMED = 1; |
||
254 | const STATUS_NEUTRAL = 0; |
||
255 | const STATUS_DELETED = -1; |
||
256 | const STATUS_MODERATION = -2; |
||
257 | const STATUS_ABORTED = -4; |
||
258 | const STATUS_CANCELED = -8; |
||
259 | |||
260 | /** |
||
261 | * Set donationId |
||
262 | * |
||
263 | * @param integer $donationId |
||
264 | * |
||
265 | * @return self |
||
266 | */ |
||
267 | public function setDonationId( $donationId ) { |
||
272 | |||
273 | /** |
||
274 | * Get donationId |
||
275 | * |
||
276 | * @return integer |
||
277 | */ |
||
278 | public function getDonationId() { |
||
281 | |||
282 | /** |
||
283 | * Set timestamp |
||
284 | * |
||
285 | * @param \DateTime $timestamp |
||
286 | * |
||
287 | * @return self |
||
288 | */ |
||
289 | public function setTimestamp( $timestamp ) { |
||
294 | |||
295 | /** |
||
296 | * Get timestamp |
||
297 | * |
||
298 | * @return \DateTime |
||
299 | */ |
||
300 | public function getTimestamp() { |
||
303 | |||
304 | /** |
||
305 | * Set salutation |
||
306 | * |
||
307 | * @param string $salutation |
||
308 | * |
||
309 | * @return self |
||
310 | */ |
||
311 | public function setSalutation( $salutation ) { |
||
316 | |||
317 | /** |
||
318 | * Get salutation |
||
319 | * |
||
320 | * @return string |
||
321 | */ |
||
322 | public function getSalutation() { |
||
325 | |||
326 | /** |
||
327 | * Set company name |
||
328 | * |
||
329 | * @param string $company |
||
330 | * |
||
331 | * @return self |
||
332 | */ |
||
333 | public function setCompany( $company ) { |
||
338 | |||
339 | /** |
||
340 | * Get company name |
||
341 | * |
||
342 | * @return string |
||
343 | */ |
||
344 | public function getCompany() { |
||
347 | |||
348 | /** |
||
349 | * Set title |
||
350 | * |
||
351 | * @param string $title |
||
352 | * |
||
353 | * @return self |
||
354 | */ |
||
355 | public function setTitle( $title ) { |
||
360 | |||
361 | /** |
||
362 | * Get title |
||
363 | * |
||
364 | * @return string |
||
365 | */ |
||
366 | public function getTitle() { |
||
369 | |||
370 | /** |
||
371 | * Set name |
||
372 | * |
||
373 | * @param string $name |
||
374 | * |
||
375 | * @return self |
||
376 | */ |
||
377 | public function setName( $name ) { |
||
382 | |||
383 | /** |
||
384 | * Get name |
||
385 | * |
||
386 | * @return string |
||
387 | */ |
||
388 | public function getName() { |
||
391 | |||
392 | /** |
||
393 | * Set first name |
||
394 | * |
||
395 | * @param string $firstName |
||
396 | * |
||
397 | * @return self |
||
398 | */ |
||
399 | public function setFirstName( $firstName ) { |
||
405 | |||
406 | /** |
||
407 | * Get first name |
||
408 | * |
||
409 | * @return string |
||
410 | */ |
||
411 | public function getFirstName() { |
||
414 | |||
415 | /** |
||
416 | * Set last name |
||
417 | * |
||
418 | * @param string $lastName |
||
419 | * |
||
420 | * @return self |
||
421 | */ |
||
422 | public function setLastName( $lastName ) { |
||
428 | |||
429 | /** |
||
430 | * Get last name |
||
431 | * |
||
432 | * @return string |
||
433 | */ |
||
434 | public function getLastName() { |
||
437 | |||
438 | /** |
||
439 | * Sets the full name |
||
440 | */ |
||
441 | public function setNameFromParts( $vorname, $nachname) { |
||
447 | |||
448 | /** |
||
449 | * Set address (street, etc) |
||
450 | * |
||
451 | * @param string $address |
||
452 | * |
||
453 | * @return self |
||
454 | */ |
||
455 | public function setAddress( $address ) { |
||
460 | |||
461 | /** |
||
462 | * Get address (street, etc) |
||
463 | * |
||
464 | * @return string |
||
465 | */ |
||
466 | public function getAddress() { |
||
469 | |||
470 | /** |
||
471 | * Set postcode |
||
472 | * |
||
473 | * @param string $postcode |
||
474 | * |
||
475 | * @return self |
||
476 | */ |
||
477 | public function setPostcode( $postcode ) { |
||
482 | |||
483 | /** |
||
484 | * Get postcode |
||
485 | * |
||
486 | * @return string |
||
487 | */ |
||
488 | public function getPostcode() { |
||
491 | |||
492 | /** |
||
493 | * Set city |
||
494 | * |
||
495 | * @param string $city |
||
496 | * |
||
497 | * @return self |
||
498 | */ |
||
499 | public function setCity( $city ) { |
||
504 | |||
505 | /** |
||
506 | * Get city |
||
507 | * |
||
508 | * @return string |
||
509 | */ |
||
510 | public function getCity() { |
||
513 | |||
514 | /** |
||
515 | * Set email |
||
516 | * |
||
517 | * @param string $email |
||
518 | * |
||
519 | * @return self |
||
520 | */ |
||
521 | public function setEmail( $email ) { |
||
526 | |||
527 | /** |
||
528 | * Get email |
||
529 | * |
||
530 | * @return string |
||
531 | */ |
||
532 | public function getEmail() { |
||
535 | |||
536 | /** |
||
537 | * Set phone |
||
538 | * |
||
539 | * @param string $phone |
||
540 | * |
||
541 | * @return self |
||
542 | */ |
||
543 | public function setPhone( $phone ) { |
||
548 | |||
549 | /** |
||
550 | * Get phone |
||
551 | * |
||
552 | * @return string |
||
553 | */ |
||
554 | public function getPhone() { |
||
557 | |||
558 | /** |
||
559 | * Set dob |
||
560 | * |
||
561 | * @param \DateTime $dob |
||
562 | * |
||
563 | * @return self |
||
564 | */ |
||
565 | public function setDob( $dob ) { |
||
570 | |||
571 | /** |
||
572 | * Get dob |
||
573 | * |
||
574 | * @return \DateTime |
||
575 | */ |
||
576 | public function getDob() { |
||
579 | |||
580 | /** |
||
581 | * Set wikimediumShipping |
||
582 | * |
||
583 | * @param string $wikimediumShipping |
||
584 | * |
||
585 | * @return self |
||
586 | */ |
||
587 | public function setWikimediumShipping( $wikimediumShipping ) { |
||
592 | |||
593 | /** |
||
594 | * Get wikimediumShipping |
||
595 | * |
||
596 | * @return string |
||
597 | */ |
||
598 | public function getWikimediumShipping() { |
||
601 | |||
602 | /** |
||
603 | * Set membershipType |
||
604 | * |
||
605 | * @param string $membershipType |
||
606 | * |
||
607 | * @return self |
||
608 | */ |
||
609 | public function setMembershipType( $membershipType ) { |
||
614 | |||
615 | /** |
||
616 | * Get membershipType |
||
617 | * |
||
618 | * @return string |
||
619 | */ |
||
620 | public function getMembershipType() { |
||
623 | |||
624 | /** |
||
625 | * Set membershipFee |
||
626 | * |
||
627 | * @param integer $membershipFee |
||
628 | * |
||
629 | * @return self |
||
630 | */ |
||
631 | public function setMembershipFee( $membershipFee ) { |
||
636 | |||
637 | /** |
||
638 | * Get membershipFee |
||
639 | * |
||
640 | * @return integer |
||
641 | */ |
||
642 | public function getMembershipFee() { |
||
645 | |||
646 | /** |
||
647 | * Set membershipFeeInterval |
||
648 | * |
||
649 | * @param integer $membershipFeeInterval |
||
650 | * |
||
651 | * @return self |
||
652 | */ |
||
653 | public function setMembershipFeeInterval($membershipFeeInterval) { |
||
658 | |||
659 | /** |
||
660 | * Get membershipFeeInterval |
||
661 | * |
||
662 | * @return integer |
||
663 | */ |
||
664 | public function getMembershipFeeInterval() { |
||
667 | |||
668 | |||
669 | /** |
||
670 | * Set accountNumber |
||
671 | * |
||
672 | * @param string $accountNumber |
||
673 | * |
||
674 | * @return self |
||
675 | */ |
||
676 | public function setAccountNumber( $accountNumber ) { |
||
681 | |||
682 | /** |
||
683 | * Get accountNumber |
||
684 | * |
||
685 | * @return string |
||
686 | */ |
||
687 | public function getAccountNumber() { |
||
690 | |||
691 | /** |
||
692 | * Set bankName |
||
693 | * |
||
694 | * @param string $bankName |
||
695 | * |
||
696 | * @return self |
||
697 | */ |
||
698 | public function setBankName( $bankName ) { |
||
703 | |||
704 | /** |
||
705 | * Get bankName |
||
706 | * |
||
707 | * @return string |
||
708 | */ |
||
709 | public function getBankName() { |
||
712 | |||
713 | /** |
||
714 | * Set bankCode |
||
715 | * |
||
716 | * @param string $bankCode |
||
717 | * |
||
718 | * @return self |
||
719 | */ |
||
720 | public function setBankCode( $bankCode ) { |
||
725 | |||
726 | /** |
||
727 | * Get bankCode |
||
728 | * |
||
729 | * @return string |
||
730 | */ |
||
731 | public function getBankCode() { |
||
734 | |||
735 | /** |
||
736 | * Set iban |
||
737 | * |
||
738 | * @param string $iban |
||
739 | * |
||
740 | * @return self |
||
741 | */ |
||
742 | public function setIban( $iban ) { |
||
747 | |||
748 | /** |
||
749 | * Get iban |
||
750 | * |
||
751 | * @return string |
||
752 | */ |
||
753 | public function getIban() { |
||
756 | |||
757 | /** |
||
758 | * Set bic |
||
759 | * |
||
760 | * @param string $bic |
||
761 | * |
||
762 | * @return self |
||
763 | */ |
||
764 | public function setBic( $bic ) { |
||
769 | |||
770 | /** |
||
771 | * Get bic |
||
772 | * |
||
773 | * @return string |
||
774 | */ |
||
775 | public function getBic() { |
||
778 | |||
779 | /** |
||
780 | * Set accountHolder |
||
781 | * |
||
782 | * @param string $accountHolder |
||
783 | * |
||
784 | * @return self |
||
785 | */ |
||
786 | public function setAccountHolder( $accountHolder ) { |
||
791 | |||
792 | /** |
||
793 | * Get accountHolder |
||
794 | * |
||
795 | * @return string |
||
796 | */ |
||
797 | public function getAccountHolder() { |
||
800 | |||
801 | /** |
||
802 | * Set comment |
||
803 | * |
||
804 | * @param string $comment |
||
805 | * |
||
806 | * @return self |
||
807 | */ |
||
808 | public function setComment( $comment ) { |
||
813 | |||
814 | /** |
||
815 | * Get comment |
||
816 | * |
||
817 | * @return string |
||
818 | */ |
||
819 | public function getComment() { |
||
822 | |||
823 | /** |
||
824 | * Set export |
||
825 | * |
||
826 | * @param \DateTime $export |
||
827 | * |
||
828 | * @return self |
||
829 | */ |
||
830 | public function setExport( $export ) { |
||
835 | |||
836 | /** |
||
837 | * Get export |
||
838 | * |
||
839 | * @return \DateTime |
||
840 | */ |
||
841 | public function getExport() { |
||
844 | |||
845 | /** |
||
846 | * Set backup |
||
847 | * |
||
848 | * @param \DateTime $backup |
||
849 | * |
||
850 | * @return self |
||
851 | */ |
||
852 | public function setBackup( $backup ) { |
||
857 | |||
858 | /** |
||
859 | * Get backup |
||
860 | * |
||
861 | * @return \DateTime |
||
862 | */ |
||
863 | public function getBackup() { |
||
866 | |||
867 | /** |
||
868 | * Set wikilogin |
||
869 | * |
||
870 | * @param boolean $wikilogin |
||
871 | * |
||
872 | * @return self |
||
873 | */ |
||
874 | public function setWikilogin( $wikilogin ) { |
||
879 | |||
880 | /** |
||
881 | * Get wikilogin |
||
882 | * |
||
883 | * @return boolean |
||
884 | */ |
||
885 | public function getWikilogin() { |
||
888 | |||
889 | /** |
||
890 | * Set tracking |
||
891 | * |
||
892 | * @param string $tracking |
||
893 | * |
||
894 | * @return self |
||
895 | */ |
||
896 | public function setTracking( $tracking ) { |
||
901 | |||
902 | /** |
||
903 | * Get tracking |
||
904 | * |
||
905 | * @return string |
||
906 | */ |
||
907 | public function getTracking() { |
||
910 | |||
911 | /** |
||
912 | * Set status |
||
913 | * |
||
914 | * @param integer $status |
||
915 | * |
||
916 | * @return self |
||
917 | */ |
||
918 | public function setStatus( $status ) { |
||
923 | |||
924 | /** |
||
925 | * Get status |
||
926 | * |
||
927 | * @return integer |
||
928 | */ |
||
929 | public function getStatus() { |
||
932 | |||
933 | /** |
||
934 | * Set country |
||
935 | * |
||
936 | * @param string $country |
||
937 | * |
||
938 | * @return self |
||
939 | */ |
||
940 | public function setCountry( $country ) { |
||
945 | |||
946 | /** |
||
947 | * Get country |
||
948 | * |
||
949 | * @return string |
||
950 | */ |
||
951 | public function getCountry() { |
||
954 | |||
955 | /** |
||
956 | * Set data |
||
957 | * |
||
958 | * @param string $data |
||
959 | * @return self |
||
960 | */ |
||
961 | public function setData( $data ) { |
||
966 | |||
967 | /** |
||
968 | * Get data |
||
969 | * |
||
970 | * @return string |
||
971 | */ |
||
972 | public function getData() { |
||
975 | |||
976 | /** |
||
977 | * Get id |
||
978 | * |
||
979 | * @return integer |
||
980 | */ |
||
981 | public function getId() { |
||
984 | |||
985 | public function isUnconfirmed() { |
||
988 | |||
989 | public function log( $message ) { |
||
994 | |||
995 | private function getDataArray() { |
||
998 | |||
999 | private function saveDataArray( array $dataArray ) { |
||
1003 | } |
||
1004 |