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 $extra_data; |
||
54 | protected $transactions_log_table; |
||
55 | |||
56 | /** |
||
57 | * Constructor |
||
58 | * |
||
59 | * @param \phpbb\db\driver\driver_interface $db Database object |
||
60 | * @param \phpbb\user $user User object |
||
61 | * @param string $table_name Name of the table used to store data |
||
62 | * |
||
63 | * @access public |
||
64 | */ |
||
65 | public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $table_name) |
||
109 | |||
110 | /** |
||
111 | * Checks if the txn_id exists for this transaction |
||
112 | * |
||
113 | * @return int $this->data['transaction_id'] Transaction identifier; 0 if the transaction doesn't exist |
||
114 | * @access public |
||
115 | */ |
||
116 | public function transaction_exists() |
||
117 | { |
||
118 | $sql = 'SELECT transaction_id |
||
119 | FROM ' . $this->transactions_log_table . " |
||
120 | WHERE txn_id = '" . $this->db->sql_escape($this->data['txn_id']) . "'"; |
||
121 | $this->db->sql_query($sql); |
||
122 | |||
123 | return $this->db->sql_fetchfield('transaction_id'); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Get PayPal transaction id |
||
128 | * |
||
129 | * @return string |
||
130 | * @access public |
||
131 | */ |
||
132 | public function get_txn_id() |
||
136 | |||
137 | /** |
||
138 | * Get PayPal receiver ID |
||
139 | * |
||
140 | * @return string |
||
141 | * @access public |
||
142 | */ |
||
143 | public function get_receiver_id() |
||
147 | |||
148 | /** |
||
149 | * Get PayPal receiver e-mail |
||
150 | * |
||
151 | * @return string |
||
152 | * @access public |
||
153 | */ |
||
154 | public function get_receiver_email() |
||
158 | |||
159 | /** |
||
160 | * Get PayPal receiver ID |
||
161 | * |
||
162 | * @return string |
||
163 | * @access public |
||
164 | */ |
||
165 | public function get_residence_country() |
||
169 | |||
170 | /** |
||
171 | * Get PayPal business (same as receiver ID or receiver_email) |
||
172 | * |
||
173 | * @return string |
||
174 | * @access public |
||
175 | */ |
||
176 | public function get_business() |
||
180 | |||
181 | /** |
||
182 | * Get PayPal transaction status |
||
183 | * |
||
184 | * @return bool |
||
185 | * @access public |
||
186 | */ |
||
187 | public function get_confirmed() |
||
191 | |||
192 | /** |
||
193 | * Get Test IPN status |
||
194 | * |
||
195 | * @return bool |
||
196 | * @access public |
||
197 | */ |
||
198 | public function get_test_ipn() |
||
202 | |||
203 | /** |
||
204 | * Get PayPal transaction type |
||
205 | * |
||
206 | * @return string |
||
207 | * @access public |
||
208 | */ |
||
209 | public function get_txn_type() |
||
213 | |||
214 | /** |
||
215 | * Get PayPal parent transaction ID (in case of refund) |
||
216 | * |
||
217 | * @return string |
||
218 | * @access public |
||
219 | */ |
||
220 | public function get_parent_txn_id() |
||
224 | |||
225 | /** |
||
226 | * Get PayPal payer e-mail |
||
227 | * |
||
228 | * @return string |
||
229 | * @access public |
||
230 | */ |
||
231 | public function get_payer_email() |
||
235 | |||
236 | /** |
||
237 | * Get PayPal payer account ID |
||
238 | * |
||
239 | * @return string |
||
240 | * @access public |
||
241 | */ |
||
242 | public function get_payer_id() |
||
246 | |||
247 | /** |
||
248 | * Get PayPal payer Status (such as unverified/verified) |
||
249 | * |
||
250 | * @return string |
||
251 | * @access public |
||
252 | */ |
||
253 | public function get_payer_status() |
||
257 | |||
258 | /** |
||
259 | * Get PayPal payer first name |
||
260 | * |
||
261 | * @return string |
||
262 | * @access public |
||
263 | */ |
||
264 | public function get_first_name() |
||
268 | |||
269 | /** |
||
270 | * Get PayPal payer last name |
||
271 | * |
||
272 | * @return string |
||
273 | * @access public |
||
274 | */ |
||
275 | public function get_last_name() |
||
279 | |||
280 | /** |
||
281 | * Get member user_id |
||
282 | * |
||
283 | * @return integer |
||
284 | * @access public |
||
285 | */ |
||
286 | public function get_user_id() |
||
290 | |||
291 | /** |
||
292 | * Get member username |
||
293 | * |
||
294 | * @return string |
||
295 | * @access public |
||
296 | */ |
||
297 | public function get_username() |
||
301 | |||
302 | /** |
||
303 | * Get PayPal payer last name |
||
304 | * |
||
305 | * @return string |
||
306 | * @access public |
||
307 | */ |
||
308 | public function get_custom() |
||
312 | |||
313 | /** |
||
314 | * Get PayPal item name |
||
315 | * |
||
316 | * @return string |
||
317 | * @access public |
||
318 | */ |
||
319 | public function get_item_name() |
||
323 | |||
324 | /** |
||
325 | * Get PayPal item number (contains user_id) |
||
326 | * |
||
327 | * @return string |
||
328 | * @access public |
||
329 | */ |
||
330 | public function get_item_number() |
||
334 | |||
335 | /** |
||
336 | * Get PayPal currency name (eg: USD, EUR, etc.) |
||
337 | * |
||
338 | * @return string |
||
339 | * @access public |
||
340 | */ |
||
341 | public function get_mc_currency() |
||
345 | |||
346 | /** |
||
347 | * Get PayPal fees |
||
348 | * |
||
349 | * @return float |
||
350 | * @access public |
||
351 | */ |
||
352 | public function get_mc_fee() |
||
356 | |||
357 | /** |
||
358 | * Get PayPal amount |
||
359 | * This is the amount of donation received before fees |
||
360 | * |
||
361 | * @return float |
||
362 | * @access public |
||
363 | */ |
||
364 | public function get_mc_gross() |
||
368 | |||
369 | /** |
||
370 | * Get Net amount |
||
371 | * This is the amount of donation received after fees |
||
372 | * |
||
373 | * @return float |
||
1 ignored issue
–
show
|
|||
374 | * @access public |
||
375 | */ |
||
376 | public function get_net_amount() |
||
380 | |||
381 | /** |
||
382 | * Get PayPal payment date |
||
383 | * |
||
384 | * @return integer |
||
385 | * @access public |
||
386 | */ |
||
387 | public function get_payment_date() |
||
391 | |||
392 | /** |
||
393 | * Get PayPal payment status |
||
394 | * |
||
395 | * @return string |
||
396 | * @access public |
||
397 | */ |
||
398 | public function get_payment_status() |
||
402 | |||
403 | /** |
||
404 | * Get PayPal payment type |
||
405 | * |
||
406 | * @return string |
||
407 | * @access public |
||
408 | */ |
||
409 | public function get_payment_type() |
||
413 | |||
414 | /** |
||
415 | * Get PayPal settle amount |
||
416 | * This is in case or the currency of the Payer is not in the same currency of the Receiver |
||
417 | * |
||
418 | * @return float |
||
1 ignored issue
–
show
|
|||
419 | * @access public |
||
420 | */ |
||
421 | public function get_settle_amount() |
||
425 | |||
426 | /** |
||
427 | * Get PayPal settle currency |
||
428 | * |
||
429 | * @return string |
||
430 | * @access public |
||
431 | */ |
||
432 | public function get_settle_currency() |
||
436 | |||
437 | /** |
||
438 | * Get PayPal exchange rate |
||
439 | * This is when the donation don’t use the same currency defined by the receiver |
||
440 | * |
||
441 | * @return string |
||
442 | * @access public |
||
443 | */ |
||
444 | public function get_exchange_rate() |
||
448 | |||
449 | /** |
||
450 | * Set PayPal transaction id |
||
451 | * |
||
452 | * @param string $txn_id |
||
453 | * |
||
454 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
455 | * @access public |
||
456 | */ |
||
457 | public function set_txn_id($txn_id) |
||
463 | |||
464 | /** |
||
465 | * Set PayPal receiver ID |
||
466 | * |
||
467 | * @param string $receiver_id |
||
468 | * |
||
469 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
470 | * @access public |
||
471 | */ |
||
472 | public function set_receiver_id($receiver_id) |
||
478 | |||
479 | /** |
||
480 | * Set PayPal receiver e-mail |
||
481 | * |
||
482 | * @param string $receiver_email |
||
483 | * |
||
484 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
485 | * @access public |
||
486 | */ |
||
487 | public function set_receiver_email($receiver_email) |
||
493 | |||
494 | /** |
||
495 | * Set PayPal receiver ID |
||
496 | * |
||
497 | * @param string $residence_country |
||
498 | * |
||
499 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
500 | * @access public |
||
501 | */ |
||
502 | public function set_residence_country($residence_country) |
||
508 | |||
509 | /** |
||
510 | * Set PayPal business (same as receiver ID or receiver_email) |
||
511 | * |
||
512 | * @param string $business |
||
513 | * |
||
514 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
515 | * @access public |
||
516 | */ |
||
517 | public function set_business($business) |
||
523 | |||
524 | /** |
||
525 | * Set PayPal transaction status |
||
526 | * |
||
527 | * @param bool $confirmed |
||
528 | * |
||
529 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
530 | * @access public |
||
531 | */ |
||
532 | public function set_confirmed($confirmed) |
||
538 | |||
539 | /** |
||
540 | * Set Test IPN status |
||
541 | * |
||
542 | * @param bool $test_ipn |
||
543 | * |
||
544 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
545 | * @access public |
||
546 | */ |
||
547 | public function set_test_ipn($test_ipn) |
||
553 | |||
554 | /** |
||
555 | * Set PayPal transaction type |
||
556 | * |
||
557 | * @param string $txn_type |
||
558 | * |
||
559 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
560 | * @access public |
||
561 | */ |
||
562 | public function set_txn_type($txn_type) |
||
568 | |||
569 | /** |
||
570 | * Set PayPal parent transaction ID (in case of refund) |
||
571 | * |
||
572 | * @param string $parent_txn_id |
||
573 | * |
||
574 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
575 | * @access public |
||
576 | */ |
||
577 | public function set_parent_txn_id($parent_txn_id) |
||
583 | |||
584 | /** |
||
585 | * Set PayPal payer e-mail |
||
586 | * |
||
587 | * @param string $payer_email |
||
588 | * |
||
589 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
590 | * @access public |
||
591 | */ |
||
592 | public function set_payer_email($payer_email) |
||
598 | |||
599 | /** |
||
600 | * Set PayPal payer account ID |
||
601 | * |
||
602 | * @param string $payer_id |
||
603 | * |
||
604 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
605 | * @access public |
||
606 | */ |
||
607 | public function set_payer_id($payer_id) |
||
613 | |||
614 | /** |
||
615 | * Set PayPal payer Status (such as unverified/verified) |
||
616 | * |
||
617 | * @param string $payer_status |
||
618 | * |
||
619 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
620 | * @access public |
||
621 | */ |
||
622 | public function set_payer_status($payer_status) |
||
628 | |||
629 | /** |
||
630 | * Set PayPal payer first name |
||
631 | * |
||
632 | * @param string $first_name |
||
633 | * |
||
634 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
635 | * @access public |
||
636 | */ |
||
637 | public function set_first_name($first_name) |
||
643 | |||
644 | /** |
||
645 | * Set PayPal payer last name |
||
646 | * |
||
647 | * @param string $last_name |
||
648 | * |
||
649 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
650 | * @access public |
||
651 | */ |
||
652 | public function set_last_name($last_name) |
||
658 | |||
659 | /** |
||
660 | * Set member user_id |
||
661 | * |
||
662 | * @param integer $user_id |
||
663 | * |
||
664 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
665 | * @access public |
||
666 | */ |
||
667 | public function set_user_id($user_id) |
||
673 | |||
674 | /** |
||
675 | * Set member username |
||
676 | * |
||
677 | * @param string $username |
||
678 | * |
||
679 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
680 | * @access public |
||
681 | */ |
||
682 | public function set_username($username) |
||
688 | |||
689 | /** |
||
690 | * Set PayPal payer last name |
||
691 | * |
||
692 | * @param string $custom |
||
693 | * |
||
694 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
695 | * @access public |
||
696 | */ |
||
697 | public function set_custom($custom) |
||
703 | |||
704 | /** |
||
705 | * Set PayPal item name |
||
706 | * |
||
707 | * @param string $item_name |
||
708 | * |
||
709 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
710 | * @access public |
||
711 | */ |
||
712 | public function set_item_name($item_name) |
||
718 | |||
719 | /** |
||
720 | * Set PayPal item number (contains user_id) |
||
721 | * |
||
722 | * @param string $item_number |
||
723 | * |
||
724 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
725 | * @access public |
||
726 | */ |
||
727 | public function set_item_number($item_number) |
||
733 | |||
734 | /** |
||
735 | * Set PayPal currency name (eg: USD, EUR, etc.) |
||
736 | * |
||
737 | * @param string $mc_currency |
||
738 | * |
||
739 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
740 | * @access public |
||
741 | */ |
||
742 | public function set_mc_currency($mc_currency) |
||
748 | |||
749 | /** |
||
750 | * Set PayPal fees |
||
751 | * |
||
752 | * @param float $mc_fee |
||
753 | * |
||
754 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
755 | * @access public |
||
756 | */ |
||
757 | public function set_mc_fee($mc_fee) |
||
763 | |||
764 | /** |
||
765 | * Set PayPal amount |
||
766 | * This is the amount of donation received before fees |
||
767 | * |
||
768 | * @param float $mc_gross |
||
769 | * |
||
770 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
771 | * @access public |
||
772 | */ |
||
773 | public function set_mc_gross($mc_gross) |
||
779 | |||
780 | /** |
||
781 | * Set Net amount |
||
782 | * This is the amount of donation received after fees |
||
783 | * |
||
784 | * @param float $net_amount |
||
785 | * |
||
786 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
787 | * @access public |
||
788 | */ |
||
789 | public function set_net_amount($net_amount) |
||
795 | |||
796 | /** |
||
797 | * Set PayPal payment date |
||
798 | * |
||
799 | * @param integer $payment_date |
||
800 | * |
||
801 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
802 | * @access public |
||
803 | */ |
||
804 | public function set_payment_date($payment_date) |
||
810 | |||
811 | /** |
||
812 | * Set PayPal payment status |
||
813 | * |
||
814 | * @param string $payment_status |
||
815 | * |
||
816 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
817 | * @access public |
||
818 | */ |
||
819 | public function set_payment_status($payment_status) |
||
825 | |||
826 | /** |
||
827 | * Set PayPal payment type |
||
828 | * |
||
829 | * @param string $payment_type |
||
830 | * |
||
831 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
832 | * @access public |
||
833 | */ |
||
834 | public function set_payment_type($payment_type) |
||
840 | |||
841 | /** |
||
842 | * Set PayPal settle amount |
||
843 | * This is in case or the currency of the Payer is not in the same currency of the Receiver |
||
844 | * |
||
845 | * @param float $settle_amount |
||
846 | * |
||
847 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
848 | * @access public |
||
849 | */ |
||
850 | public function set_settle_amount($settle_amount) |
||
856 | |||
857 | /** |
||
858 | * Set PayPal settle currency |
||
859 | * |
||
860 | * @param string $settle_currency |
||
861 | * |
||
862 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
863 | * @access public |
||
864 | */ |
||
865 | public function set_settle_currency($settle_currency) |
||
871 | |||
872 | /** |
||
873 | * Set PayPal exchange rate |
||
874 | * This is when the donation don’t use the same currency defined by the receiver |
||
875 | * |
||
876 | * @param string $exchange_rate |
||
877 | * |
||
878 | * @return transactions $this object for chaining calls; load()->set()->save() |
||
879 | * @access public |
||
880 | */ |
||
881 | public function set_exchange_rate($exchange_rate) |
||
887 | } |
||
888 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.