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 |
||
| 24 | class Give_Tools_Delete_Donors extends Give_Batch_Export { |
||
| 25 | |||
| 26 | var $request; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Used to store donation id's that are going to get deleted. |
||
| 30 | * @var array. |
||
| 31 | * @since 1.8.12 |
||
| 32 | */ |
||
| 33 | var $donation_key = 'give_temp_delete_donation_ids'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Used to store donors id's that are going to get deleted. |
||
| 37 | * @var array. |
||
| 38 | * @since 1.8.12 |
||
| 39 | */ |
||
| 40 | var $donor_key = 'give_temp_delete_donor_ids'; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Used to store the step where the step will be. ( 'count', 'donations', 'donors' ). |
||
| 44 | * @var array. |
||
| 45 | * @since 1.8.12 |
||
| 46 | */ |
||
| 47 | var $step_key = 'give_temp_delete_step'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Used to store to get the page count in the loop. |
||
| 51 | * @var array. |
||
| 52 | * @since 1.8.12 |
||
| 53 | */ |
||
| 54 | var $step_on_key = 'give_temp_delete_step_on'; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Contain total number of step . |
||
| 58 | * @var array. |
||
| 59 | * @since 1.8.12 |
||
| 60 | */ |
||
| 61 | var $total_step; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Counting contain total number of step that completed. |
||
| 65 | * @var array. |
||
| 66 | * @since 1.8.12 |
||
| 67 | */ |
||
| 68 | var $step_completed; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Our export type. Used for export-type specific filters/actions |
||
| 72 | * @var string |
||
| 73 | * @since 1.8.12 |
||
| 74 | */ |
||
| 75 | public $export_type = ''; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Allows for a non-form batch processing to be run. |
||
| 79 | * @since 1.8.12 |
||
| 80 | * @var boolean |
||
| 81 | */ |
||
| 82 | public $is_void = true; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Sets the number of items to pull on each step |
||
| 86 | * @since 1.8.12 |
||
| 87 | * @var integer |
||
| 88 | */ |
||
| 89 | public $per_step = 10; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Set's all the donors id's |
||
| 93 | * @since 1.8.12 |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | public $donor_ids = array(); |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Get the Export Data |
||
| 100 | * |
||
| 101 | * @access public |
||
| 102 | * @since 1.8.12 |
||
| 103 | * @global object $wpdb Used to query the database using the WordPress Database API |
||
| 104 | * |
||
| 105 | * @return array|bool $data The data for the CSV file |
||
| 106 | */ |
||
| 107 | public function pre_fetch() { |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Will Update or Add the donation and donors ids in the with option table for there respected key. |
||
| 143 | * |
||
| 144 | * @param string $step On which the current ajax is running. |
||
| 145 | * @param array $donation_ids Contain the list of all the donation id's that has being add before this |
||
| 146 | * @param array $donor_ids Contain the list of all the donors id's that has being add before this |
||
| 147 | */ |
||
| 148 | private function count( $step, $donation_ids = array(), $donor_ids = array() ) { |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Return the calculated completion percentage. |
||
| 217 | * |
||
| 218 | * @since 1.8.12 |
||
| 219 | * @return int |
||
| 220 | */ |
||
| 221 | public function get_percentage_complete() { |
||
| 224 | |||
| 225 | View Code Duplication | public function process_step() { |
|
| 254 | |||
| 255 | /** |
||
| 256 | * Get the Export Data |
||
| 257 | * |
||
| 258 | * @access public |
||
| 259 | * @since 1.8.12 |
||
| 260 | * @global object $wpdb Used to query the database using the WordPress Database API |
||
| 261 | * |
||
| 262 | * @return array|bool $data The data for the CSV file |
||
| 263 | */ |
||
| 264 | public function get_data() { |
||
| 355 | |||
| 356 | public function get_delete_ids( $donation_ids, $page ) { |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Given a key, get the information from the Database Directly |
||
| 378 | * |
||
| 379 | * @since 1.8.12 |
||
| 380 | * |
||
| 381 | * @param string $key The option_name |
||
| 382 | * |
||
| 383 | * @return mixed Returns the data from the database |
||
| 384 | */ |
||
| 385 | public function get_option( $key, $defalut_value = false ) { |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Give a key, store the value |
||
| 391 | * |
||
| 392 | * @since 1.8.12s |
||
| 393 | * |
||
| 394 | * @param string $key The option_name |
||
| 395 | * @param mixed $value The value to store |
||
| 396 | * |
||
| 397 | * @return void |
||
| 398 | */ |
||
| 399 | public function update_option( $key, $value ) { |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Delete an option |
||
| 405 | * |
||
| 406 | * @since 1.8.12 |
||
| 407 | * |
||
| 408 | * @param string $key The option_name to delete |
||
| 409 | * |
||
| 410 | * @return void |
||
| 411 | */ |
||
| 412 | public function delete_option( $key ) { |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Get the current step in number. |
||
| 418 | * |
||
| 419 | * There are three step to delete the total donor first counting, second deleting donotion and third deleting donors. |
||
| 420 | * |
||
| 421 | * @return int|string |
||
| 422 | */ |
||
| 423 | private function get_step() { |
||
| 435 | |||
| 436 | /** |
||
| 437 | * Get the current $page value in the ajax. |
||
| 438 | */ |
||
| 439 | private function get_step_page() { |
||
| 442 | } |
||
| 443 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.