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() { |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Return the calculated completion percentage |
||
| 78 | * |
||
| 79 | * @since 1.5 |
||
| 80 | * @return int |
||
| 81 | */ |
||
| 82 | public function get_percentage_complete() { |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Set the properties specific to the payments export |
||
| 102 | * |
||
| 103 | * @since 1.5 |
||
| 104 | * |
||
| 105 | * @param array $request The Form Data passed into the batch processing |
||
| 106 | */ |
||
| 107 | public function set_properties( $request ) { |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Process a step |
||
| 112 | * |
||
| 113 | * @since 1.5 |
||
| 114 | * @return bool |
||
| 115 | */ |
||
| 116 | View Code Duplication | public function process_step() { |
|
| 145 | |||
| 146 | /** |
||
| 147 | * Headers |
||
| 148 | */ |
||
| 149 | View Code Duplication | public function headers() { |
|
| 156 | |||
| 157 | /** |
||
| 158 | * Perform the export |
||
| 159 | * |
||
| 160 | * @access public |
||
| 161 | * @since 1.5 |
||
| 162 | * @return void |
||
| 163 | */ |
||
| 164 | public function export() { |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Pre Fetch |
||
| 174 | */ |
||
| 175 | public function pre_fetch() { |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Given a key, get the information from the Database Directly |
||
| 215 | * |
||
| 216 | * @since 1.5 |
||
| 217 | * |
||
| 218 | * @param string $key The option_name |
||
| 219 | * |
||
| 220 | * @return mixed Returns the data from the database |
||
| 221 | */ |
||
| 222 | View Code Duplication | 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 ) { |
|
| 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 | } |
||
| 283 |
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.