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 |
||
29 | class Give_Gateway_Reports_Table extends WP_List_Table { |
||
30 | |||
31 | /** |
||
32 | * @var int Number of items per page |
||
33 | * @since 1.0 |
||
34 | */ |
||
35 | public $per_page = 30; |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Get things started |
||
40 | * |
||
41 | * @since 1.0 |
||
42 | * @see WP_List_Table::__construct() |
||
43 | */ |
||
44 | View Code Duplication | public function __construct() { |
|
55 | |||
56 | /** |
||
57 | * This function renders most of the columns in the list table. |
||
58 | * |
||
59 | * @access public |
||
60 | * @since 1.0 |
||
61 | * |
||
62 | * @param array $item Contains all the data of the form |
||
63 | * @param string $column_name The name of the column |
||
64 | * |
||
65 | * @return string Column Name |
||
66 | */ |
||
67 | public function column_default( $item, $column_name ) { |
||
125 | |||
126 | /** |
||
127 | * Retrieve the table columns |
||
128 | * |
||
129 | * @access public |
||
130 | * @since 1.0 |
||
131 | * @return array $columns Array of all the list table columns |
||
132 | */ |
||
133 | public function get_columns() { |
||
144 | |||
145 | /** |
||
146 | * Get the sortable columns |
||
147 | * |
||
148 | * @access public |
||
149 | * @since 1.8.12 |
||
150 | * @return array Array of all the sortable columns |
||
151 | */ |
||
152 | public function get_sortable_columns() { |
||
157 | |||
158 | |||
159 | /** |
||
160 | * Retrieve the current page number |
||
161 | * |
||
162 | * @access public |
||
163 | * @since 1.0 |
||
164 | * @return int Current page number |
||
165 | */ |
||
166 | public function get_paged() { |
||
169 | |||
170 | |||
171 | /** |
||
172 | * Outputs the reporting views |
||
173 | * |
||
174 | * @access public |
||
175 | * @since 1.0 |
||
176 | * @return void |
||
177 | */ |
||
178 | public function bulk_actions( $which = '' ) { |
||
181 | |||
182 | /** |
||
183 | * Generate the table navigation above or below the table |
||
184 | * |
||
185 | * @since 1.0 |
||
186 | * @access protected |
||
187 | * |
||
188 | * @param string $which |
||
189 | */ |
||
190 | View Code Duplication | protected function display_tablenav( $which ) { |
|
220 | |||
221 | /** |
||
222 | * Reorder User Defined Array |
||
223 | * |
||
224 | * @param $old_value |
||
225 | * @param $new_value |
||
226 | * |
||
227 | * @access public |
||
228 | * @since 1.8.12 |
||
229 | * |
||
230 | * @return int |
||
231 | */ |
||
232 | public function give_sort_total_donations( $old_value, $new_value ) { |
||
244 | |||
245 | |||
246 | /** |
||
247 | * Build all the reports data |
||
248 | * |
||
249 | * @access public |
||
250 | * @since 1.0 |
||
251 | * @return array $reports_data All the data for donor reports |
||
252 | */ |
||
253 | public function reports_data() { |
||
276 | |||
277 | /** |
||
278 | * Setup the final data for the table |
||
279 | * |
||
280 | * @access public |
||
281 | * @since 1.0 |
||
282 | * @uses Give_Gateway_Reports_Table::get_columns() |
||
283 | * @uses Give_Gateway_Reports_Table::get_sortable_columns() |
||
284 | * @uses Give_Gateway_Reports_Table::reports_data() |
||
285 | * @return void |
||
286 | */ |
||
287 | public function prepare_items() { |
||
298 | } |
||
299 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.