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_Form_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 = 30; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Sets the donation form ID to recalculate |
||
| 48 | * @since 1.5 |
||
| 49 | * @var integer |
||
| 50 | */ |
||
| 51 | protected $form_id = null; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Get the Export Data |
||
| 55 | * |
||
| 56 | * @access public |
||
| 57 | * @since 1.5 |
||
| 58 | * |
||
| 59 | * @return bool |
||
| 60 | */ |
||
| 61 | public function get_data() { |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Return the calculated completion percentage |
||
| 120 | * |
||
| 121 | * @since 1.5 |
||
| 122 | * @return int |
||
| 123 | */ |
||
| 124 | public function get_percentage_complete() { |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Set the properties specific to the payments export |
||
| 162 | * |
||
| 163 | * @since 1.5 |
||
| 164 | * |
||
| 165 | * @param array $request The Form Data passed into the batch processing |
||
| 166 | */ |
||
| 167 | public function set_properties( $request ) { |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Process a step |
||
| 173 | * |
||
| 174 | * @since 1.5 |
||
| 175 | * @return bool |
||
| 176 | */ |
||
| 177 | public function process_step() { |
||
| 198 | |||
| 199 | View Code Duplication | public function headers() { |
|
| 200 | ignore_user_abort( true ); |
||
| 201 | |||
| 202 | if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
||
| 203 | set_time_limit( 0 ); |
||
| 204 | } |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Perform the export |
||
| 209 | * |
||
| 210 | * @access public |
||
| 211 | * @since 1.5 |
||
| 212 | * @return void |
||
| 213 | */ |
||
| 214 | public function export() { |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Given a key, get the information from the Database Directly |
||
| 224 | * |
||
| 225 | * @since 1.5 |
||
| 226 | * |
||
| 227 | * @param string $key The option_name |
||
| 228 | * |
||
| 229 | * @return mixed Returns the data from the database |
||
| 230 | */ |
||
| 231 | private function get_stored_data( $key ) { |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Give a key, store the value |
||
| 240 | * |
||
| 241 | * @since 1.5 |
||
| 242 | * |
||
| 243 | * @param string $key The option_name |
||
| 244 | * @param mixed $value The value to store |
||
| 245 | * |
||
| 246 | * @return void |
||
| 247 | */ |
||
| 248 | View Code Duplication | private function store_data( $key, $value ) { |
|
| 249 | global $wpdb; |
||
| 250 | |||
| 251 | $value = maybe_serialize( $value ); |
||
| 252 | |||
| 253 | $data = array( |
||
| 254 | 'option_name' => $key, |
||
| 255 | 'option_value' => $value, |
||
| 256 | 'autoload' => 'no', |
||
| 257 | ); |
||
| 258 | |||
| 259 | $formats = array( |
||
| 260 | '%s', |
||
| 261 | '%s', |
||
| 262 | '%s', |
||
| 263 | ); |
||
| 264 | |||
| 265 | $wpdb->replace( $wpdb->options, $data, $formats ); |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Delete an option |
||
| 270 | * |
||
| 271 | * @since 1.5 |
||
| 272 | * |
||
| 273 | * @param string $key The option_name to delete |
||
| 274 | * |
||
| 275 | * @return void |
||
| 276 | */ |
||
| 277 | private function delete_data( $key ) { |
||
| 281 | |||
| 282 | } |