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'); } |
||
11 | class EE_Cron_Tasks extends EE_BASE { |
||
12 | |||
13 | /** |
||
14 | * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
||
15 | * so we'll set our retry time for just over 10 minutes to avoid that |
||
16 | */ |
||
17 | const reschedule_timeout = 605; |
||
18 | |||
19 | |||
20 | /** |
||
21 | * @var EE_Cron_Tasks |
||
22 | */ |
||
23 | private static $_instance; |
||
24 | |||
25 | |||
26 | |||
27 | /** |
||
28 | * @return EE_Cron_Tasks |
||
29 | */ |
||
30 | public static function instance() { |
||
36 | |||
37 | |||
38 | |||
39 | /** |
||
40 | * @access private |
||
41 | * @return EE_Cron_Tasks |
||
|
|||
42 | */ |
||
43 | private function __construct() { |
||
82 | |||
83 | |||
84 | |||
85 | /** |
||
86 | * @access protected |
||
87 | * @return void |
||
88 | */ |
||
89 | public static function log_scheduled_ee_crons() { |
||
112 | |||
113 | |||
114 | |||
115 | |||
116 | /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
||
117 | |||
118 | |||
119 | /** |
||
120 | * array of TXN IDs and the payment |
||
121 | * @var array |
||
122 | */ |
||
123 | protected static $_update_transactions_with_payment = array(); |
||
124 | |||
125 | |||
126 | |||
127 | /** |
||
128 | * schedule_update_transaction_with_payment |
||
129 | * |
||
130 | * sets a wp_schedule_single_event() for updating any TXNs that may |
||
131 | * require updating due to recently received payments |
||
132 | * |
||
133 | * @param int $timestamp |
||
134 | * @param int $TXN_ID |
||
135 | * @param int $PAY_ID |
||
136 | */ |
||
137 | View Code Duplication | public static function schedule_update_transaction_with_payment( |
|
154 | |||
155 | |||
156 | |||
157 | /** |
||
158 | * setup_update_for_transaction_with_payment |
||
159 | * |
||
160 | * this is the callback for the action hook: |
||
161 | * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
||
162 | * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
||
163 | * The passed TXN_ID and associated payment gets added to an array, and then |
||
164 | * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
||
165 | * 'shutdown' which will actually handle the processing of any |
||
166 | * transactions requiring updating, because doing so now would be too early |
||
167 | * and the required resources may not be available |
||
168 | * |
||
169 | * @param int $TXN_ID |
||
170 | * @param int $PAY_ID |
||
171 | */ |
||
172 | View Code Duplication | public static function setup_update_for_transaction_with_payment( $TXN_ID = 0, $PAY_ID = 0 ) { |
|
183 | |||
184 | |||
185 | |||
186 | /** |
||
187 | * update_transaction_with_payment |
||
188 | * |
||
189 | * loops through the self::$_abandoned_transactions array |
||
190 | * and attempts to finalize any TXNs that have not been completed |
||
191 | * but have had their sessions expired, most likely due to a user not |
||
192 | * returning from an off-site payment gateway |
||
193 | * |
||
194 | * @throws \EE_Error |
||
195 | */ |
||
196 | public static function update_transaction_with_payment() { |
||
228 | |||
229 | |||
230 | |||
231 | /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
||
232 | |||
233 | |||
234 | |||
235 | /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
||
236 | |||
237 | |||
238 | |||
239 | /** |
||
240 | * array of TXN IDs |
||
241 | * @var array |
||
242 | */ |
||
243 | protected static $_abandoned_transactions = array(); |
||
244 | |||
245 | |||
246 | |||
247 | /** |
||
248 | * schedule_finalize_abandoned_transactions_check |
||
249 | * |
||
250 | * sets a wp_schedule_single_event() for finalizing any TXNs that may |
||
251 | * have been abandoned during the registration process |
||
252 | * |
||
253 | * @param int $timestamp |
||
254 | * @param int $TXN_ID |
||
255 | */ |
||
256 | View Code Duplication | public static function schedule_finalize_abandoned_transactions_check( |
|
272 | |||
273 | |||
274 | |||
275 | /** |
||
276 | * check_for_abandoned_transactions |
||
277 | * |
||
278 | * this is the callback for the action hook: |
||
279 | * 'AHEE__EE_Cron_Tasks__espresso_finalize_abandoned_transactions' |
||
280 | * which is utilized by wp_schedule_single_event() |
||
281 | * in EE_SPCO_Reg_Step_Payment_Options::_post_payment_processing(). |
||
282 | * The passed TXN_ID gets added to an array, and then the |
||
283 | * espresso_finalize_abandoned_transactions() function is hooked into |
||
284 | * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
||
285 | * processing of any abandoned transactions, because doing so now would be |
||
286 | * too early and the required resources may not be available |
||
287 | * |
||
288 | * @param int $TXN_ID |
||
289 | */ |
||
290 | View Code Duplication | public static function check_for_abandoned_transactions( $TXN_ID = 0 ) { |
|
301 | |||
302 | |||
303 | |||
304 | /** |
||
305 | * finalize_abandoned_transactions |
||
306 | |||
307 | * loops through the self::$_abandoned_transactions array |
||
308 | * and attempts to finalize any TXNs that have not been completed |
||
309 | * but have had their sessions expired, most likely due to a user not |
||
310 | * returning from an off-site payment gateway |
||
311 | * |
||
312 | * @throws \EE_Error |
||
313 | */ |
||
314 | public static function finalize_abandoned_transactions() { |
||
351 | |||
352 | |||
353 | |||
354 | /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
||
355 | |||
356 | |||
357 | |||
358 | /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
||
359 | |||
360 | //when a transaction is initially made, schedule this check. |
||
361 | //if it has NO REG data by the time it has expired, forget about it |
||
362 | public static function clean_out_junk_transactions() { |
||
369 | |||
370 | |||
371 | } |
||
372 | // End of file EE_Cron_Tasks.core.php |
||
374 |
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.