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_Income 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 = 100; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Constructor. |
||
| 48 | */ |
||
| 49 | public function __construct( $_step = 1 ) { |
||
| 54 | /** |
||
| 55 | * Get the Export Data |
||
| 56 | * |
||
| 57 | * @access public |
||
| 58 | * @since 1.5 |
||
| 59 | * |
||
| 60 | * @return bool |
||
| 61 | */ |
||
| 62 | public function get_data() { |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Return the calculated completion percentage |
||
| 114 | * |
||
| 115 | * @since 1.5 |
||
| 116 | * @return int |
||
| 117 | */ |
||
| 118 | public function get_percentage_complete() { |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Set the properties specific to the payments export |
||
| 147 | * |
||
| 148 | * @since 1.5 |
||
| 149 | * |
||
| 150 | * @param array $request The Form Data passed into the batch processing |
||
| 151 | */ |
||
| 152 | public function set_properties( $request ) { |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Process a step |
||
| 157 | * |
||
| 158 | * @since 1.5 |
||
| 159 | * @return bool |
||
| 160 | */ |
||
| 161 | public function process_step() { |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Headers. |
||
| 185 | */ |
||
| 186 | public function headers() { |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Perform the export |
||
| 192 | * |
||
| 193 | * @access public |
||
| 194 | * @since 1.5 |
||
| 195 | * @return void |
||
| 196 | */ |
||
| 197 | public function export() { |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Given a key, get the information from the Database Directly |
||
| 207 | * |
||
| 208 | * @since 1.5 |
||
| 209 | * |
||
| 210 | * @param string $key The option_name |
||
| 211 | * |
||
| 212 | * @return mixed Returns the data from the database |
||
| 213 | */ |
||
| 214 | View Code Duplication | private function get_stored_data( $key ) { |
|
| 229 | |||
| 230 | /** |
||
| 231 | * Give a key, store the value |
||
| 232 | * |
||
| 233 | * @since 1.5 |
||
| 234 | * |
||
| 235 | * @param string $key The option_name |
||
| 236 | * @param mixed $value The value to store |
||
| 237 | * |
||
| 238 | * @return void |
||
| 239 | */ |
||
| 240 | View Code Duplication | private function store_data( $key, $value ) { |
|
| 259 | |||
| 260 | /** |
||
| 261 | * Delete an option |
||
| 262 | * |
||
| 263 | * @since 1.5 |
||
| 264 | * |
||
| 265 | * @param string $key The option_name to delete |
||
| 266 | * |
||
| 267 | * @return void |
||
| 268 | */ |
||
| 269 | private function delete_data( $key ) { |
||
| 273 | |||
| 274 | } |
||
| 275 |