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 |
||
| 22 | class Give_Tools_Recount_Donor_Stats extends Give_Batch_Export { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Our export type. Used for export-type specific filters/actions. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | * @since 1.5 |
||
| 29 | */ |
||
| 30 | public $export_type = ''; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Allows for a non-form batch processing to be run. |
||
| 34 | * |
||
| 35 | * @since 1.5 |
||
| 36 | * @var boolean |
||
| 37 | */ |
||
| 38 | public $is_void = true; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Sets the number of items to pull on each step |
||
| 42 | * |
||
| 43 | * @since 1.5 |
||
| 44 | * @var integer |
||
| 45 | */ |
||
| 46 | public $per_step = 5; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Get the Export Data |
||
| 50 | * |
||
| 51 | * @access public |
||
| 52 | * @since 1.5 |
||
| 53 | * |
||
| 54 | * @return array $data The data for the CSV file |
||
| 55 | */ |
||
| 56 | public function get_data() { |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Return the calculated completion percentage |
||
| 148 | * |
||
| 149 | * @since 1.5 |
||
| 150 | * @return int |
||
| 151 | */ |
||
| 152 | public function get_percentage_complete() { |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Set the properties specific to the payments export |
||
| 178 | * |
||
| 179 | * @since 1.5 |
||
| 180 | * |
||
| 181 | * @param array $request The Form Data passed into the batch processing |
||
| 182 | */ |
||
| 183 | public function set_properties( $request ) { |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Process a step |
||
| 188 | * |
||
| 189 | * @since 1.5 |
||
| 190 | * @return bool |
||
| 191 | */ |
||
| 192 | public function process_step() { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Headers |
||
| 216 | */ |
||
| 217 | View Code Duplication | public function headers() { |
|
| 218 | ignore_user_abort( true ); |
||
| 219 | |||
| 220 | if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
||
| 221 | set_time_limit( 0 ); |
||
| 222 | } |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Perform the export |
||
| 227 | * |
||
| 228 | * @access public |
||
| 229 | * @since 1.5 |
||
| 230 | * @return void |
||
| 231 | */ |
||
| 232 | public function export() { |
||
| 239 | |||
| 240 | } |
||
| 241 |