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 { |
||
| 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 |
||
| 82 | * the query is run to convert them to the proper syntax. |
||
| 83 | * |
||
| 84 | * @since 1.8.14 |
||
| 85 | * @access public |
||
| 86 | * |
||
| 87 | * @param $args array The array of arguments that can be passed in and used for setting up this payment query. |
||
| 88 | */ |
||
| 89 | public function __construct( $args = array() ) { |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Modify the query/query arguments before we retrieve donors. |
||
| 116 | * |
||
| 117 | * @since 1.8.14 |
||
| 118 | * @access public |
||
| 119 | * |
||
| 120 | * @return void |
||
| 121 | */ |
||
| 122 | public function init() { |
||
| 124 | |||
| 125 | |||
| 126 | /** |
||
| 127 | * Retrieve donors. |
||
| 128 | * |
||
| 129 | * The query can be modified in two ways; either the action before the |
||
| 130 | * query is run, or the filter on the arguments (existing mainly for backwards |
||
| 131 | * compatibility). |
||
| 132 | * |
||
| 133 | * @since 1.8.14 |
||
| 134 | * @access public |
||
| 135 | * |
||
| 136 | * @global wpdb $wpdb |
||
| 137 | * |
||
| 138 | * @return array |
||
| 139 | */ |
||
| 140 | public function get_donors() { |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Get sql query from queried array. |
||
| 180 | * |
||
| 181 | * @since 2.0 |
||
| 182 | * @access public |
||
| 183 | * |
||
| 184 | * @global wpdb $wpdb |
||
| 185 | * @return string |
||
| 186 | */ |
||
| 187 | public function get_sql() { |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Set query where clause. |
||
| 234 | * |
||
| 235 | * @since 1.8.14 |
||
| 236 | * @access private |
||
| 237 | * |
||
| 238 | * @global wpdb $wpdb |
||
| 239 | * @return string |
||
| 240 | */ |
||
| 241 | private function get_where_query() { |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Set email where clause. |
||
| 268 | * |
||
| 269 | * @since 1.8.14 |
||
| 270 | * @access private |
||
| 271 | * |
||
| 272 | * @global wpdb $wpdb |
||
| 273 | * @return string |
||
| 274 | */ |
||
| 275 | private function get_where_email() { |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Set donor where clause. |
||
| 299 | * |
||
| 300 | * @since 1.8.14 |
||
| 301 | * @access private |
||
| 302 | * |
||
| 303 | * @global wpdb $wpdb |
||
| 304 | * @return string |
||
| 305 | */ |
||
| 306 | View Code Duplication | private function get_where_donor() { |
|
| 321 | |||
| 322 | /** |
||
| 323 | * Set date where clause. |
||
| 324 | * |
||
| 325 | * @since 1.8.14 |
||
| 326 | * @access private |
||
| 327 | * |
||
| 328 | * @global wpdb $wpdb |
||
| 329 | * @return string |
||
| 330 | */ |
||
| 331 | private function get_where_date() { |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Set search where clause. |
||
| 361 | * |
||
| 362 | * @since 1.8.14 |
||
| 363 | * @access private |
||
| 364 | * |
||
| 365 | * @global wpdb $wpdb |
||
| 366 | * @return string |
||
| 367 | */ |
||
| 368 | private function get_where_search() { |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Set user where clause. |
||
| 393 | * |
||
| 394 | * @since 1.8.14 |
||
| 395 | * @access private |
||
| 396 | * |
||
| 397 | * @global wpdb $wpdb |
||
| 398 | * @return string |
||
| 399 | */ |
||
| 400 | View Code Duplication | private function get_where_user() { |
|
| 415 | |||
| 416 | /** |
||
| 417 | * Set orderby query |
||
| 418 | * |
||
| 419 | * @since 1.8.14 |
||
| 420 | * @access private |
||
| 421 | * |
||
| 422 | * @return string |
||
| 423 | */ |
||
| 424 | private function get_order_query() { |
||
| 446 | } |
||
| 447 |