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 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 | * Get sql query from queried array. |
||
171 | * |
||
172 | * @since 2.0 |
||
173 | * @access public |
||
174 | * |
||
175 | * @global wpdb $wpdb |
||
176 | * @return string |
||
177 | */ |
||
178 | public function get_sql() { |
||
216 | |||
217 | /** |
||
218 | * Set query where clause. |
||
219 | * |
||
220 | * @since 1.8.14 |
||
221 | * @access private |
||
222 | * |
||
223 | * @global wpdb $wpdb |
||
224 | * @return string |
||
225 | */ |
||
226 | private function get_where_query() { |
||
249 | |||
250 | /** |
||
251 | * Set email where clause. |
||
252 | * |
||
253 | * @since 1.8.14 |
||
254 | * @access private |
||
255 | * |
||
256 | * @global wpdb $wpdb |
||
257 | * @return string |
||
258 | */ |
||
259 | private function get_where_email() { |
||
280 | |||
281 | /** |
||
282 | * Set donor where clause. |
||
283 | * |
||
284 | * @since 1.8.14 |
||
285 | * @access private |
||
286 | * |
||
287 | * @global wpdb $wpdb |
||
288 | * @return string |
||
289 | */ |
||
290 | View Code Duplication | private function get_where_donor() { |
|
305 | |||
306 | /** |
||
307 | * Set date where clause. |
||
308 | * |
||
309 | * @since 1.8.14 |
||
310 | * @access private |
||
311 | * |
||
312 | * @global wpdb $wpdb |
||
313 | * @return string |
||
314 | */ |
||
315 | private function get_where_date() { |
||
330 | |||
331 | /** |
||
332 | * Set search where clause. |
||
333 | * |
||
334 | * @since 1.8.14 |
||
335 | * @access private |
||
336 | * |
||
337 | * @global wpdb $wpdb |
||
338 | * @return string |
||
339 | */ |
||
340 | private function get_where_search() { |
||
362 | |||
363 | /** |
||
364 | * Set user where clause. |
||
365 | * |
||
366 | * @since 1.8.14 |
||
367 | * @access private |
||
368 | * |
||
369 | * @global wpdb $wpdb |
||
370 | * @return string |
||
371 | */ |
||
372 | View Code Duplication | private function get_where_user() { |
|
387 | |||
388 | /** |
||
389 | * Set orderby query |
||
390 | * |
||
391 | * @since 1.8.14 |
||
392 | * @access private |
||
393 | * |
||
394 | * @return string |
||
395 | */ |
||
396 | private function get_order_query() { |
||
418 | } |
||
419 |