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_Delete_Test_Transactions 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 | * 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 | * |
||
| 53 | * @return array|bool $data The data for the CSV file |
||
| 54 | */ |
||
| 55 | public function get_data() { |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Return the calculated completion percentage |
||
| 132 | * |
||
| 133 | * @since 1.5 |
||
| 134 | * @return int |
||
| 135 | */ |
||
| 136 | public function get_percentage_complete() { |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Set the properties specific to the payments export |
||
| 156 | * |
||
| 157 | * @since 1.5 |
||
| 158 | * |
||
| 159 | * @param array $request The Form Data passed into the batch processing |
||
| 160 | */ |
||
| 161 | public function set_properties( $request ) { |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Process a step |
||
| 166 | * |
||
| 167 | * @since 1.5 |
||
| 168 | * @return bool |
||
| 169 | */ |
||
| 170 | View Code Duplication | public function process_step() { |
|
| 199 | |||
| 200 | /** |
||
| 201 | * Headers |
||
| 202 | */ |
||
| 203 | View Code Duplication | public function headers() { |
|
| 210 | |||
| 211 | /** |
||
| 212 | * Perform the export |
||
| 213 | * |
||
| 214 | * @access public |
||
| 215 | * @since 1.5 |
||
| 216 | * @return void |
||
| 217 | */ |
||
| 218 | public function export() { |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Pre Fetch |
||
| 228 | */ |
||
| 229 | public function pre_fetch() { |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Given a key, get the information from the Database Directly |
||
| 269 | * |
||
| 270 | * @since 1.5 |
||
| 271 | * |
||
| 272 | * @param string $key The option_name |
||
| 273 | * |
||
| 274 | * @return mixed Returns the data from the database |
||
| 275 | */ |
||
| 276 | private function get_stored_data( $key ) { |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Give a key, store the value |
||
| 285 | * |
||
| 286 | * @since 1.5 |
||
| 287 | * |
||
| 288 | * @param string $key The option_name |
||
| 289 | * @param mixed $value The value to store |
||
| 290 | * |
||
| 291 | * @return void |
||
| 292 | */ |
||
| 293 | View Code Duplication | private function store_data( $key, $value ) { |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Delete an option |
||
| 315 | * |
||
| 316 | * @since 1.5 |
||
| 317 | * |
||
| 318 | * @param string $key The option_name to delete |
||
| 319 | * |
||
| 320 | * @return void |
||
| 321 | */ |
||
| 322 | private function delete_data( $key ) { |
||
| 326 | |||
| 327 | } |
||
| 328 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.