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 |
||
| 23 | class Give_Tools_Recount_Single_Customer_Stats extends Give_Batch_Export { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Our export type. Used for export-type specific filters/actions |
||
| 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 | * @since 1.5 |
||
| 35 | * @var boolean |
||
| 36 | */ |
||
| 37 | public $is_void = true; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Sets the number of items to pull on each step |
||
| 41 | * @since 1.5 |
||
| 42 | * @var integer |
||
| 43 | */ |
||
| 44 | public $per_step = 10; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get the Export Data |
||
| 48 | * |
||
| 49 | * @access public |
||
| 50 | * @since 1.5 |
||
| 51 | * @global object $wpdb Used to query the database using the WordPress Database API |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | public function get_data() { |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Return the calculated completion percentage |
||
| 109 | * |
||
| 110 | * @since 1.5 |
||
| 111 | * @return int |
||
| 112 | */ |
||
| 113 | public function get_percentage_complete() { |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Set the properties specific to the payments export |
||
| 133 | * |
||
| 134 | * @since 1.5 |
||
| 135 | * |
||
| 136 | * @param array $request The Form Data passed into the batch processing |
||
| 137 | */ |
||
| 138 | public function set_properties( $request ) { |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Process a step |
||
| 144 | * |
||
| 145 | * @since 1.5 |
||
| 146 | * @return bool |
||
| 147 | */ |
||
| 148 | public function process_step() { |
||
| 201 | |||
| 202 | View Code Duplication | public function headers() { |
|
| 203 | ignore_user_abort( true ); |
||
| 204 | |||
| 205 | if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
||
| 206 | set_time_limit( 0 ); |
||
| 207 | } |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Perform the export |
||
| 212 | * |
||
| 213 | * @access public |
||
| 214 | * @since 1.5 |
||
| 215 | * @return void |
||
| 216 | */ |
||
| 217 | public function export() { |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Zero out the data on step one |
||
| 227 | * |
||
| 228 | * @access public |
||
| 229 | * @since 1.5 |
||
| 230 | * @return void |
||
| 231 | */ |
||
| 232 | public function pre_fetch() { |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Given a key, get the information from the Database Directly |
||
| 272 | * |
||
| 273 | * @since 1.5 |
||
| 274 | * |
||
| 275 | * @param string $key The option_name |
||
| 276 | * |
||
| 277 | * @return mixed Returns the data from the database |
||
| 278 | */ |
||
| 279 | private function get_stored_data( $key ) { |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Give a key, store the value |
||
| 288 | * |
||
| 289 | * @since 1.5 |
||
| 290 | * |
||
| 291 | * @param string $key The option_name |
||
| 292 | * @param mixed $value The value to store |
||
| 293 | * |
||
| 294 | * @return void |
||
| 295 | */ |
||
| 296 | View Code Duplication | private function store_data( $key, $value ) { |
|
| 297 | global $wpdb; |
||
| 298 | |||
| 299 | $value = maybe_serialize( $value ); |
||
| 300 | |||
| 301 | $data = array( |
||
| 302 | 'option_name' => $key, |
||
| 303 | 'option_value' => $value, |
||
| 304 | 'autoload' => 'no', |
||
| 305 | ); |
||
| 306 | |||
| 307 | $formats = array( |
||
| 308 | '%s', |
||
| 309 | '%s', |
||
| 310 | '%s', |
||
| 311 | ); |
||
| 312 | |||
| 313 | $wpdb->replace( $wpdb->options, $data, $formats ); |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Delete an option |
||
| 318 | * |
||
| 319 | * @since 1.5 |
||
| 320 | * |
||
| 321 | * @param string $key The option_name to delete |
||
| 322 | * |
||
| 323 | * @return void |
||
| 324 | */ |
||
| 325 | private function delete_data( $key ) { |
||
| 329 | |||
| 330 | } |
||
| 331 |