Complex classes like transactions 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 transactions, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class transactions extends main |
||
20 | { |
||
21 | /** |
||
22 | * Data for this entity |
||
23 | * |
||
24 | * @var array |
||
25 | * transaction_id |
||
26 | * txn_id |
||
27 | * txn_type |
||
28 | * confirmed |
||
29 | * user_id |
||
30 | * item_name |
||
31 | * item_number |
||
32 | * business |
||
33 | * receiver_id |
||
34 | * receiver_email |
||
35 | * payment_status |
||
36 | * mc_gross |
||
37 | * mc_fee |
||
38 | * mc_currency |
||
39 | * settle_amount |
||
40 | * settle_currency |
||
41 | * net_amount |
||
42 | * exchange_rate |
||
43 | * payment_type |
||
44 | * payment_date |
||
45 | * payer_id |
||
46 | * payer_email |
||
47 | * payer_status |
||
48 | * first_name |
||
49 | * last_name |
||
50 | * @access protected |
||
51 | */ |
||
52 | protected $data; |
||
53 | protected $transactions_log_table; |
||
54 | |||
55 | /** |
||
56 | * Constructor |
||
57 | * |
||
58 | * @param \phpbb\db\driver\driver_interface $db Database object |
||
59 | * @param \phpbb\user $user User object |
||
60 | * @param string $table_name Name of the table used to store data |
||
61 | * |
||
62 | * @access public |
||
63 | */ |
||
64 | public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $table_name) |
||
108 | |||
109 | /** |
||
110 | * Check the txn_id exist from the database for this transaction |
||
111 | * |
||
112 | * @return int $this->data['txn_id'] Transaction identifier; 0 if the transaction doesn't exist |
||
113 | * @access public |
||
114 | */ |
||
115 | public function transaction_exists() |
||
124 | |||
125 | /** |
||
126 | * Get PayPal transaction id |
||
127 | * |
||
128 | * @return string |
||
129 | * @access public |
||
130 | */ |
||
131 | public function get_txn_id() |
||
135 | |||
136 | /** |
||
137 | * Get PayPal receiver ID |
||
138 | * |
||
139 | * @return string |
||
140 | * @access public |
||
141 | */ |
||
142 | public function get_receiver_id() |
||
146 | |||
147 | /** |
||
148 | * Get PayPal receiver e-mail |
||
149 | * |
||
150 | * @return string |
||
151 | * @access public |
||
152 | */ |
||
153 | public function get_receiver_email() |
||
157 | |||
158 | /** |
||
159 | * Get PayPal receiver ID |
||
160 | * |
||
161 | * @return string |
||
162 | * @access public |
||
163 | */ |
||
164 | public function get_residence_country() |
||
168 | |||
169 | /** |
||
170 | * Get PayPal business (same as receiver ID or receiver_email) |
||
171 | * |
||
172 | * @return string |
||
173 | * @access public |
||
174 | */ |
||
175 | public function get_business() |
||
179 | |||
180 | /** |
||
181 | * Get PayPal transaction status |
||
182 | * |
||
183 | * @return bool |
||
184 | * @access public |
||
185 | */ |
||
186 | public function get_confirmed() |
||
190 | |||
191 | /** |
||
192 | * Get Test IPN status |
||
193 | * |
||
194 | * @return bool |
||
195 | * @access public |
||
196 | */ |
||
197 | public function get_test_ipn() |
||
201 | |||
202 | /** |
||
203 | * Get PayPal transaction type |
||
204 | * |
||
205 | * @return string |
||
206 | * @access public |
||
207 | */ |
||
208 | public function get_txn_type() |
||
212 | |||
213 | /** |
||
214 | * Get PayPal parent transaction ID (in case of refund) |
||
215 | * |
||
216 | * @return string |
||
217 | * @access public |
||
218 | */ |
||
219 | public function get_parent_txn_id() |
||
223 | |||
224 | /** |
||
225 | * Get PayPal payer e-mail |
||
226 | * |
||
227 | * @return string |
||
228 | * @access public |
||
229 | */ |
||
230 | public function get_payer_email() |
||
234 | |||
235 | /** |
||
236 | * Get PayPal payer account ID |
||
237 | * |
||
238 | * @return string |
||
239 | * @access public |
||
240 | */ |
||
241 | public function get_payer_id() |
||
245 | |||
246 | /** |
||
247 | * Get PayPal payer Status (such as unverified/verified) |
||
248 | * |
||
249 | * @return string |
||
250 | * @access public |
||
251 | */ |
||
252 | public function get_payer_status() |
||
256 | |||
257 | /** |
||
258 | * Get PayPal payer first name |
||
259 | * |
||
260 | * @return string |
||
261 | * @access public |
||
262 | */ |
||
263 | public function get_first_name() |
||
267 | |||
268 | /** |
||
269 | * Get PayPal payer last name |
||
270 | * |
||
271 | * @return string |
||
272 | * @access public |
||
273 | */ |
||
274 | public function get_last_name() |
||
278 | |||
279 | /** |
||
280 | * Get member user_id |
||
281 | * |
||
282 | * @return integer |
||
283 | * @access public |
||
284 | */ |
||
285 | public function get_user_id() |
||
289 | |||
290 | /** |
||
291 | * Get PayPal payer last name |
||
292 | * |
||
293 | * @return string |
||
294 | * @access public |
||
295 | */ |
||
296 | public function get_custom() |
||
300 | |||
301 | /** |
||
302 | * Get PayPal item name |
||
303 | * |
||
304 | * @return string |
||
305 | * @access public |
||
306 | */ |
||
307 | public function get_item_name() |
||
311 | |||
312 | /** |
||
313 | * Get PayPal item number (contains user_id) |
||
314 | * |
||
315 | * @return string |
||
316 | * @access public |
||
317 | */ |
||
318 | public function get_item_number() |
||
322 | |||
323 | /** |
||
324 | * Get PayPal currency name (eg: USD, EUR, etc.) |
||
325 | * |
||
326 | * @return string |
||
327 | * @access public |
||
328 | */ |
||
329 | public function get_mc_currency() |
||
333 | |||
334 | /** |
||
335 | * Get PayPal fees |
||
336 | * |
||
337 | * @return float |
||
338 | * @access public |
||
339 | */ |
||
340 | public function get_mc_fee() |
||
344 | |||
345 | /** |
||
346 | * Get PayPal amount |
||
347 | * This is the amount of donation received before fees |
||
348 | * |
||
349 | * @return float |
||
350 | * @access public |
||
351 | */ |
||
352 | public function get_mc_gross() |
||
356 | |||
357 | /** |
||
358 | * Get Net amount |
||
359 | * This is the amount of donation received after fees |
||
360 | * |
||
361 | * @return float |
||
362 | * @access public |
||
363 | */ |
||
364 | public function get_net_amount() |
||
368 | |||
369 | /** |
||
370 | * Get PayPal payment date |
||
371 | * |
||
372 | * @return integer |
||
373 | * @access public |
||
374 | */ |
||
375 | public function get_payment_date() |
||
379 | |||
380 | /** |
||
381 | * Get PayPal payment status |
||
382 | * |
||
383 | * @return string |
||
384 | * @access public |
||
385 | */ |
||
386 | public function get_payment_status() |
||
390 | |||
391 | /** |
||
392 | * Get PayPal payment type |
||
393 | * |
||
394 | * @return string |
||
395 | * @access public |
||
396 | */ |
||
397 | public function get_payment_type() |
||
401 | |||
402 | /** |
||
403 | * Get PayPal settle amount |
||
404 | * This is in case or the currency of the Payer is not in the same currency of the Receiver |
||
405 | * |
||
406 | * @return float |
||
407 | * @access public |
||
408 | */ |
||
409 | public function get_settle_amount() |
||
413 | |||
414 | /** |
||
415 | * Get PayPal settle currency |
||
416 | * |
||
417 | * @return string |
||
418 | * @access public |
||
419 | */ |
||
420 | public function get_settle_currency() |
||
424 | |||
425 | /** |
||
426 | * Get PayPal exchange rate |
||
427 | * This is when the donation don’t use the same currency defined by the receiver |
||
428 | * |
||
429 | * @return string |
||
430 | * @access public |
||
431 | */ |
||
432 | public function get_exchange_rate() |
||
436 | |||
437 | /** |
||
438 | * Set PayPal transaction id |
||
439 | * |
||
440 | * @param string $txn_id |
||
441 | * |
||
442 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
443 | * @access public |
||
444 | */ |
||
445 | public function set_txn_id($txn_id) |
||
451 | |||
452 | /** |
||
453 | * Set PayPal receiver ID |
||
454 | * |
||
455 | * @param string $receiver_id |
||
456 | * |
||
457 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
458 | * @access public |
||
459 | */ |
||
460 | public function set_receiver_id($receiver_id) |
||
466 | |||
467 | /** |
||
468 | * Set PayPal receiver e-mail |
||
469 | * |
||
470 | * @param string $receiver_email |
||
471 | * |
||
472 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
473 | * @access public |
||
474 | */ |
||
475 | public function set_receiver_email($receiver_email) |
||
481 | |||
482 | /** |
||
483 | * Set PayPal receiver ID |
||
484 | * |
||
485 | * @param string $residence_country |
||
486 | * |
||
487 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
488 | * @access public |
||
489 | */ |
||
490 | public function set_residence_country($residence_country) |
||
496 | |||
497 | /** |
||
498 | * Set PayPal business (same as receiver ID or receiver_email) |
||
499 | * |
||
500 | * @param string $business |
||
501 | * |
||
502 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
503 | * @access public |
||
504 | */ |
||
505 | public function set_business($business) |
||
511 | |||
512 | /** |
||
513 | * Set PayPal transaction status |
||
514 | * |
||
515 | * @param bool $confirmed |
||
516 | * |
||
517 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
518 | * @access public |
||
519 | */ |
||
520 | public function set_confirmed($confirmed) |
||
526 | |||
527 | /** |
||
528 | * Set Test IPN status |
||
529 | * |
||
530 | * @param bool $test_ipn |
||
531 | * |
||
532 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
533 | * @access public |
||
534 | */ |
||
535 | public function set_test_ipn($test_ipn) |
||
541 | |||
542 | /** |
||
543 | * Set PayPal transaction type |
||
544 | * |
||
545 | * @param string $txn_type |
||
546 | * |
||
547 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
548 | * @access public |
||
549 | */ |
||
550 | public function set_txn_type($txn_type) |
||
556 | |||
557 | /** |
||
558 | * Set PayPal parent transaction ID (in case of refund) |
||
559 | * |
||
560 | * @param string $parent_txn_id |
||
561 | * |
||
562 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
563 | * @access public |
||
564 | */ |
||
565 | public function set_parent_txn_id($parent_txn_id) |
||
571 | |||
572 | /** |
||
573 | * Set PayPal payer e-mail |
||
574 | * |
||
575 | * @param string $payer_email |
||
576 | * |
||
577 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
578 | * @access public |
||
579 | */ |
||
580 | public function set_payer_email($payer_email) |
||
586 | |||
587 | /** |
||
588 | * Set PayPal payer account ID |
||
589 | * |
||
590 | * @param string $payer_id |
||
591 | * |
||
592 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
593 | * @access public |
||
594 | */ |
||
595 | public function set_payer_id($payer_id) |
||
601 | |||
602 | /** |
||
603 | * Set PayPal payer Status (such as unverified/verified) |
||
604 | * |
||
605 | * @param string $payer_status |
||
606 | * |
||
607 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
608 | * @access public |
||
609 | */ |
||
610 | public function set_payer_status($payer_status) |
||
616 | |||
617 | /** |
||
618 | * Set PayPal payer first name |
||
619 | * |
||
620 | * @param string $first_name |
||
621 | * |
||
622 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
623 | * @access public |
||
624 | */ |
||
625 | public function set_first_name($first_name) |
||
631 | |||
632 | /** |
||
633 | * Set PayPal payer last name |
||
634 | * |
||
635 | * @param string $last_name |
||
636 | * |
||
637 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
638 | * @access public |
||
639 | */ |
||
640 | public function set_last_name($last_name) |
||
646 | |||
647 | /** |
||
648 | * Set member user_id |
||
649 | * |
||
650 | * @param integer $user_id |
||
651 | * |
||
652 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
653 | * @access public |
||
654 | */ |
||
655 | public function set_user_id($user_id) |
||
661 | |||
662 | /** |
||
663 | * Set PayPal payer last name |
||
664 | * |
||
665 | * @param string $custom |
||
666 | * |
||
667 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
668 | * @access public |
||
669 | */ |
||
670 | public function set_custom($custom) |
||
676 | |||
677 | /** |
||
678 | * Set PayPal item name |
||
679 | * |
||
680 | * @param string $item_name |
||
681 | * |
||
682 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
683 | * @access public |
||
684 | */ |
||
685 | public function set_item_name($item_name) |
||
691 | |||
692 | /** |
||
693 | * Set PayPal item number (contains user_id) |
||
694 | * |
||
695 | * @param string $item_number |
||
696 | * |
||
697 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
698 | * @access public |
||
699 | */ |
||
700 | public function set_item_number($item_number) |
||
706 | |||
707 | /** |
||
708 | * Set PayPal currency name (eg: USD, EUR, etc.) |
||
709 | * |
||
710 | * @param string $mc_currency |
||
711 | * |
||
712 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
713 | * @access public |
||
714 | */ |
||
715 | public function set_mc_currency($mc_currency) |
||
721 | |||
722 | /** |
||
723 | * Set PayPal fees |
||
724 | * |
||
725 | * @param float $mc_fee |
||
726 | * |
||
727 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
728 | * @access public |
||
729 | */ |
||
730 | public function set_mc_fee($mc_fee) |
||
736 | |||
737 | /** |
||
738 | * Set PayPal amount |
||
739 | * This is the amount of donation received before fees |
||
740 | * |
||
741 | * @param float $mc_gross |
||
742 | * |
||
743 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
744 | * @access public |
||
745 | */ |
||
746 | public function set_mc_gross($mc_gross) |
||
752 | |||
753 | /** |
||
754 | * Set Net amount |
||
755 | * This is the amount of donation received after fees |
||
756 | * |
||
757 | * @param float $net_amount |
||
758 | * |
||
759 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
760 | * @access public |
||
761 | */ |
||
762 | public function set_net_amount($net_amount) |
||
768 | |||
769 | /** |
||
770 | * Set PayPal payment date |
||
771 | * |
||
772 | * @param integer $payment_date |
||
773 | * |
||
774 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
775 | * @access public |
||
776 | */ |
||
777 | public function set_payment_date($payment_date) |
||
783 | |||
784 | /** |
||
785 | * Set PayPal payment status |
||
786 | * |
||
787 | * @param string $payment_status |
||
788 | * |
||
789 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
790 | * @access public |
||
791 | */ |
||
792 | public function set_payment_status($payment_status) |
||
798 | |||
799 | /** |
||
800 | * Set PayPal payment type |
||
801 | * |
||
802 | * @param string $payment_type |
||
803 | * |
||
804 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
805 | * @access public |
||
806 | */ |
||
807 | public function set_payment_type($payment_type) |
||
813 | |||
814 | /** |
||
815 | * Set PayPal settle amount |
||
816 | * This is in case or the currency of the Payer is not in the same currency of the Receiver |
||
817 | * |
||
818 | * @param float $settle_amount |
||
819 | * |
||
820 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
821 | * @access public |
||
822 | */ |
||
823 | public function set_settle_amount($settle_amount) |
||
829 | |||
830 | /** |
||
831 | * Set PayPal settle currency |
||
832 | * |
||
833 | * @param string $settle_currency |
||
834 | * |
||
835 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
836 | * @access public |
||
837 | */ |
||
838 | public function set_settle_currency($settle_currency) |
||
844 | |||
845 | /** |
||
846 | * Set PayPal exchange rate |
||
847 | * This is when the donation don’t use the same currency defined by the receiver |
||
848 | * |
||
849 | * @param string $exchange_rate |
||
850 | * |
||
851 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
852 | * @access public |
||
853 | */ |
||
854 | public function set_exchange_rate($exchange_rate) |
||
860 | } |
||
861 |