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')) { |
||
15 | class EEM_Transaction extends EEM_Base |
||
16 | { |
||
17 | |||
18 | // private instance of the Transaction object |
||
19 | protected static $_instance; |
||
20 | |||
21 | /** |
||
22 | * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
||
23 | * but payment is pending. This is the state for transactions where payment is promised |
||
24 | * from an offline gateway. |
||
25 | */ |
||
26 | // const open_status_code = 'TPN'; |
||
27 | |||
28 | /** |
||
29 | * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
||
30 | * either due to a technical reason (server or computer crash during registration), |
||
31 | * or some other reason that prevent the collection of any useful contact information from any of the registrants |
||
32 | */ |
||
33 | const failed_status_code = 'TFL'; |
||
34 | |||
35 | /** |
||
36 | * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
||
37 | * either due to a technical reason (server or computer crash during registration), |
||
38 | * or due to an abandoned cart after registrant chose not to complete the registration process |
||
39 | * HOWEVER... |
||
40 | * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
||
41 | * registrant |
||
42 | */ |
||
43 | const abandoned_status_code = 'TAB'; |
||
44 | |||
45 | /** |
||
46 | * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
||
47 | * meaning that monies are still owing: TXN_paid < TXN_total |
||
48 | */ |
||
49 | const incomplete_status_code = 'TIN'; |
||
50 | |||
51 | /** |
||
52 | * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
||
53 | * meaning that NO monies are owing: TXN_paid == TXN_total |
||
54 | */ |
||
55 | const complete_status_code = 'TCM'; |
||
56 | |||
57 | /** |
||
58 | * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
||
59 | * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
||
60 | */ |
||
61 | const overpaid_status_code = 'TOP'; |
||
62 | |||
63 | |||
64 | /** |
||
65 | * private constructor to prevent direct creation |
||
66 | * |
||
67 | * @Constructor |
||
68 | * @access protected |
||
69 | * |
||
70 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
||
71 | * incoming timezone data that gets saved). Note this just sends the timezone info to the |
||
72 | * date time model field objects. Default is NULL (and will be assumed using the set |
||
73 | * timezone in the 'timezone_string' wp option) |
||
74 | * |
||
75 | * @return EEM_Transaction |
||
|
|||
76 | * @throws \EE_Error |
||
77 | */ |
||
78 | protected function __construct($timezone) |
||
121 | |||
122 | |||
123 | /** |
||
124 | * txn_status_array |
||
125 | * get list of transaction statuses |
||
126 | * |
||
127 | * @access public |
||
128 | * @return array |
||
129 | */ |
||
130 | public static function txn_status_array() |
||
143 | |||
144 | /** |
||
145 | * get the revenue per day for the Transaction Admin page Reports Tab |
||
146 | * |
||
147 | * @access public |
||
148 | * |
||
149 | * @param string $period |
||
150 | * |
||
151 | * @return \stdClass[] |
||
152 | */ |
||
153 | public function get_revenue_per_day_report($period = '-1 month') |
||
175 | |||
176 | |||
177 | /** |
||
178 | * get the revenue per event for the Transaction Admin page Reports Tab |
||
179 | * |
||
180 | * @access public |
||
181 | * |
||
182 | * @param string $period |
||
183 | * |
||
184 | * @throws \EE_Error |
||
185 | * @return mixed |
||
186 | */ |
||
187 | public function get_revenue_per_event_report($period = '-1 month') |
||
226 | |||
227 | |||
228 | /** |
||
229 | * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
||
230 | * $_REQUEST global variable. Either way, tries to find the current transaction (through |
||
231 | * the registration pointed to by reg_url_link), if not returns null |
||
232 | * |
||
233 | * @param string $reg_url_link |
||
234 | * |
||
235 | * @return EE_Transaction |
||
236 | */ |
||
237 | public function get_transaction_from_reg_url_link($reg_url_link = '') |
||
246 | |||
247 | |||
248 | /** |
||
249 | * Updates the provided EE_Transaction with all the applicable payments |
||
250 | * (or fetch the EE_Transaction from its ID) |
||
251 | * |
||
252 | * @deprecated |
||
253 | * |
||
254 | * @param EE_Transaction|int $transaction_obj_or_id |
||
255 | * @param boolean $save_txn whether or not to save the transaction during this function call |
||
256 | * |
||
257 | * @return boolean |
||
258 | * @throws \EE_Error |
||
259 | */ |
||
260 | View Code Duplication | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
275 | |||
276 | /** |
||
277 | * Deletes "junk" transactions that were probably added by bots. There might be TONS |
||
278 | * of these, so we are very careful to NOT select (which the models do even when deleting), |
||
279 | * and so we only use wpdb directly and NOT do any joins. |
||
280 | * The downside to this approach is that is addons are listening for object deletions |
||
281 | * on EEM_Base::delete() they won't be notified of this. |
||
282 | * @global WPDB $wpdb |
||
283 | * @return mixed |
||
284 | */ |
||
285 | public function delete_junk_transactions() |
||
345 | |||
346 | |||
347 | /** |
||
348 | * @param array $transaction_IDs |
||
349 | * |
||
350 | * @return bool |
||
351 | */ |
||
352 | public static function unset_locked_transactions(array $transaction_IDs) |
||
368 | |||
369 | |||
370 | } |
||
371 | // End of file EEM_Transaction.model.php |
||
373 |
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.