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 |
||
| 26 | class Give_Donors_Query extends Give_Stats { |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The args to pass to the give_get_donors() query |
||
| 30 | * |
||
| 31 | * @since 1.8.14 |
||
| 32 | * @access public |
||
| 33 | * |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | public $args = array(); |
||
| 37 | |||
| 38 | /** |
||
| 39 | * The donors found based on the criteria set |
||
| 40 | * |
||
| 41 | * @since 1.8.14 |
||
| 42 | * @access public |
||
| 43 | * |
||
| 44 | * @var array |
||
| 45 | */ |
||
| 46 | public $donors = array(); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The donors found based on the criteria set |
||
| 50 | * |
||
| 51 | * @since 1.8.14 |
||
| 52 | * @access public |
||
| 53 | * |
||
| 54 | * @var array |
||
| 55 | */ |
||
| 56 | public $table_name = ''; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * The donors found based on the criteria set |
||
| 60 | * |
||
| 61 | * @since 1.8.14 |
||
| 62 | * @access public |
||
| 63 | * |
||
| 64 | * @var array |
||
| 65 | */ |
||
| 66 | public $meta_table_name = ''; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * The donors found based on the criteria set |
||
| 70 | * |
||
| 71 | * @since 1.8.14 |
||
| 72 | * @access public |
||
| 73 | * |
||
| 74 | * @var array |
||
| 75 | */ |
||
| 76 | public $meta_type = ''; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Default query arguments. |
||
| 80 | * |
||
| 81 | * Not all of these are valid arguments that can be passed to WP_Query. The ones that are not, are modified before the query is run to convert them to the proper syntax. |
||
| 82 | * |
||
| 83 | * @since 1.8.14 |
||
| 84 | * @access public |
||
| 85 | * |
||
| 86 | * @param $args array The array of arguments that can be passed in and used for setting up this payment query. |
||
| 87 | */ |
||
| 88 | public function __construct( $args = array() ) { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Modify the query/query arguments before we retrieve donors. |
||
| 115 | * |
||
| 116 | * @since 1.8.14 |
||
| 117 | * @access public |
||
| 118 | * |
||
| 119 | * @return void |
||
| 120 | */ |
||
| 121 | public function init() { |
||
| 123 | |||
| 124 | |||
| 125 | /** |
||
| 126 | * Retrieve donors. |
||
| 127 | * |
||
| 128 | * The query can be modified in two ways; either the action before the |
||
| 129 | * query is run, or the filter on the arguments (existing mainly for backwards |
||
| 130 | * compatibility). |
||
| 131 | * |
||
| 132 | * @since 1.8.14 |
||
| 133 | * @access public |
||
| 134 | * |
||
| 135 | * @global wpdb $wpdb |
||
| 136 | * |
||
| 137 | * @return array |
||
| 138 | */ |
||
| 139 | public function get_donors() { |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Search |
||
| 171 | * |
||
| 172 | * @since 1.8.14 |
||
| 173 | * @access public |
||
| 174 | * |
||
| 175 | * @return void |
||
| 176 | */ |
||
| 177 | public function search() { |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Get sql query from queried array. |
||
| 194 | * |
||
| 195 | * @since 2.0 |
||
| 196 | * @access public |
||
| 197 | * |
||
| 198 | * @global wpdb $wpdb |
||
| 199 | * @return string |
||
| 200 | */ |
||
| 201 | public function get_sql() { |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Set query where clause. |
||
| 242 | * |
||
| 243 | * @since 1.8.14 |
||
| 244 | * @access private |
||
| 245 | * |
||
| 246 | * @global wpdb $wpdb |
||
| 247 | * @return string |
||
| 248 | */ |
||
| 249 | private function get_where_query() { |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Set email where clause. |
||
| 275 | * |
||
| 276 | * @since 1.8.14 |
||
| 277 | * @access private |
||
| 278 | * |
||
| 279 | * @global wpdb $wpdb |
||
| 280 | * @return string |
||
| 281 | */ |
||
| 282 | private function get_where_email() { |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Set donor where clause. |
||
| 306 | * |
||
| 307 | * @since 1.8.14 |
||
| 308 | * @access private |
||
| 309 | * |
||
| 310 | * @global wpdb $wpdb |
||
| 311 | * @return string |
||
| 312 | */ |
||
| 313 | View Code Duplication | private function get_where_donor() { |
|
| 328 | |||
| 329 | /** |
||
| 330 | * Set date where clause. |
||
| 331 | * |
||
| 332 | * @since 1.8.14 |
||
| 333 | * @access private |
||
| 334 | * |
||
| 335 | * @global wpdb $wpdb |
||
| 336 | * @return string |
||
| 337 | */ |
||
| 338 | private function get_where_date() { |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Set search where clause. |
||
| 356 | * |
||
| 357 | * @since 1.8.14 |
||
| 358 | * @access private |
||
| 359 | * |
||
| 360 | * @global wpdb $wpdb |
||
| 361 | * @return string |
||
| 362 | */ |
||
| 363 | private function get_where_search() { |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Set user where clause. |
||
| 388 | * |
||
| 389 | * @since 1.8.14 |
||
| 390 | * @access private |
||
| 391 | * |
||
| 392 | * @global wpdb $wpdb |
||
| 393 | * @return string |
||
| 394 | */ |
||
| 395 | View Code Duplication | private function get_where_user() { |
|
| 410 | |||
| 411 | /** |
||
| 412 | * Set orderby query |
||
| 413 | * |
||
| 414 | * @since 1.8.14 |
||
| 415 | * @access private |
||
| 416 | * |
||
| 417 | * @return string |
||
| 418 | */ |
||
| 419 | private function get_order_query() { |
||
| 441 | } |
||
| 442 |