Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
||
12 | class EEM_Transaction extends EEM_Base { |
||
13 | |||
14 | // private instance of the Transaction object |
||
15 | protected static $_instance = NULL; |
||
16 | |||
17 | /** |
||
18 | * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
||
19 | * but payment is pending. This is the state for transactions where payment is promised |
||
20 | * from an offline gateway. |
||
21 | */ |
||
22 | // const open_status_code = 'TPN'; |
||
23 | |||
24 | /** |
||
25 | * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
||
26 | * either due to a technical reason (server or computer crash during registration), |
||
27 | * or some other reason that prevent the collection of any useful contact information from any of the registrants |
||
28 | */ |
||
29 | const failed_status_code = 'TFL'; |
||
30 | |||
31 | /** |
||
32 | * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
||
33 | * either due to a technical reason (server or computer crash during registration), |
||
34 | * or due to an abandoned cart after registrant chose not to complete the registration process |
||
35 | * HOWEVER... |
||
36 | * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one registrant |
||
37 | */ |
||
38 | const abandoned_status_code = 'TAB'; |
||
39 | |||
40 | /** |
||
41 | * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
||
42 | * meaning that monies are still owing: TXN_paid < TXN_total |
||
43 | */ |
||
44 | const incomplete_status_code = 'TIN'; |
||
45 | |||
46 | /** |
||
47 | * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
||
48 | * meaning that NO monies are owing: TXN_paid == TXN_total |
||
49 | */ |
||
50 | const complete_status_code = 'TCM'; |
||
51 | |||
52 | /** |
||
53 | * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
||
54 | * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
||
55 | */ |
||
56 | const overpaid_status_code = 'TOP'; |
||
57 | |||
58 | |||
59 | |||
60 | |||
61 | |||
62 | /** |
||
63 | * private constructor to prevent direct creation |
||
64 | * |
||
65 | * @Constructor |
||
66 | * @access protected |
||
67 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). |
||
68 | * Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
||
69 | * @return EEM_Transaction |
||
|
|||
70 | */ |
||
71 | protected function __construct( $timezone ) { |
||
102 | |||
103 | /** |
||
104 | * get the revenue per day for the Transaction Admin page Reports Tab |
||
105 | * |
||
106 | * @access public |
||
107 | * @param string $period |
||
108 | * @return \stdClass[] |
||
109 | */ |
||
110 | public function get_revenue_per_day_report( $period = '-1 month' ) { |
||
133 | |||
134 | |||
135 | |||
136 | /** |
||
137 | * get the revenue per event for the Transaction Admin page Reports Tab |
||
138 | * |
||
139 | * @access public |
||
140 | * @param string $period |
||
141 | * @throws \EE_Error |
||
142 | * @return mixed |
||
143 | */ |
||
144 | public function get_revenue_per_event_report( $period = '-1 month' ) { |
||
167 | |||
168 | |||
169 | |||
170 | |||
171 | |||
172 | |||
173 | /** |
||
174 | * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
||
175 | * $_REQUEST global variable. Either way, tries to find the current transaction (through |
||
176 | * the registration pointed to by reg_url_link), if not returns null |
||
177 | * @param string $reg_url_link |
||
178 | * @return EE_Transaction |
||
179 | */ |
||
180 | public function get_transaction_from_reg_url_link( $reg_url_link = '' ){ |
||
187 | |||
188 | |||
189 | |||
190 | |||
191 | |||
192 | |||
193 | |||
194 | /** |
||
195 | * Updates the provided EE_Transaction with all the applicable payments |
||
196 | * (or fetch the EE_Transaction from its ID) |
||
197 | * |
||
198 | * @deprecated |
||
199 | * @param EE_Transaction | int $transaction_obj_or_id |
||
200 | * @param boolean $save_txn whether or not to save the transaction during this function call |
||
201 | * @return boolean |
||
202 | */ |
||
203 | View Code Duplication | public function update_based_on_payments( $transaction_obj_or_id, $save_txn = TRUE ){ |
|
213 | |||
214 | /** |
||
215 | * Deletes "junk" transactions that were probably added by bots. There might be TONS |
||
216 | * of these, so we are very careful to NOT select (which the models do even when deleting), |
||
217 | * and so we only use wpdb directly and NOT do any joins. |
||
218 | * The downside to this approach is that is addons are listening for object deletions |
||
219 | * on EEM_Base::delete() they won't be notified of this. |
||
220 | * @global WPDB $wpdb |
||
221 | * @return mixed |
||
222 | */ |
||
223 | public function delete_junk_transactions() { |
||
278 | |||
279 | |||
280 | |||
281 | |||
282 | } |
||
283 | // End of file EEM_Transaction.model.php |
||
285 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.