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_Update_Log_Table extends WP_List_Table { |
||
30 | /** |
||
31 | * Number of items per page |
||
32 | * |
||
33 | * @var int |
||
34 | * @since 2.0.1 |
||
35 | */ |
||
36 | public $per_page = 30; |
||
37 | |||
38 | /** |
||
39 | * Get things started |
||
40 | * |
||
41 | * @since 2.0.1 |
||
42 | * @see WP_List_Table::__construct() |
||
43 | */ |
||
44 | View Code Duplication | public function __construct() { |
|
54 | |||
55 | /** |
||
56 | * Show the search field |
||
57 | * |
||
58 | * @since 2.0.1 |
||
59 | * @access public |
||
60 | * |
||
61 | * @param string $text Label for the search box |
||
62 | * @param string $input_id ID of the search box |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | public function search_box( $text, $input_id ) { |
||
68 | |||
69 | /** |
||
70 | * Retrieve the table columns |
||
71 | * |
||
72 | * @access public |
||
73 | * @since 2.0.1 |
||
74 | * |
||
75 | * @return array $columns Array of all the list table columns |
||
76 | */ |
||
77 | public function get_columns() { |
||
86 | |||
87 | /** |
||
88 | * This function renders most of the columns in the list table. |
||
89 | * |
||
90 | * @access public |
||
91 | * @since 2.0.1 |
||
92 | * |
||
93 | * @param array $item Contains all the data of the discount code |
||
94 | * @param string $column_name The name of the column |
||
95 | * |
||
96 | * @return string Column Name |
||
97 | */ |
||
98 | public function column_default( $item, $column_name ) { |
||
111 | |||
112 | /** |
||
113 | * Output Error Message column |
||
114 | * |
||
115 | * @access public |
||
116 | * @since 2.0.1 |
||
117 | * |
||
118 | * @param array $item Contains all the data of the log |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | public function column_details( $item ) { |
||
146 | |||
147 | |||
148 | /** |
||
149 | * Display Tablenav (extended) |
||
150 | * |
||
151 | * Display the table navigation above or below the table even when no items in the logs, so nav doesn't disappear |
||
152 | * |
||
153 | * @see : https://github.com/WordImpress/Give/issues/564 |
||
154 | * |
||
155 | * @since 1.4.1 |
||
156 | * @access protected |
||
157 | * |
||
158 | * @param string $which |
||
159 | */ |
||
160 | View Code Duplication | protected function display_tablenav( $which ) { |
|
179 | |||
180 | /** |
||
181 | * Retrieve the current page number |
||
182 | * |
||
183 | * @access public |
||
184 | * @since 2.0.1 |
||
185 | * |
||
186 | * @return int Current page number |
||
187 | */ |
||
188 | public function get_paged() { |
||
191 | |||
192 | /** |
||
193 | * Outputs the log views |
||
194 | * |
||
195 | * @param string $which Top or Bottom. |
||
196 | * |
||
197 | * @access public |
||
198 | * @since 2.0.1 |
||
199 | * |
||
200 | * @return void |
||
201 | */ |
||
202 | function bulk_actions( $which = '' ) { |
||
204 | |||
205 | /** |
||
206 | * Gets the log entries for the current view |
||
207 | * |
||
208 | * @access public |
||
209 | * @since 2.0.1 |
||
210 | * |
||
211 | * @return array $logs_data Array of all the Log entires |
||
212 | */ |
||
213 | public function get_logs() { |
||
239 | |||
240 | /** |
||
241 | * Setup the final data for the table |
||
242 | * |
||
243 | * @access public |
||
244 | * @since 2.0.1 |
||
245 | * @uses Give_Update_Log_Table::get_columns() |
||
246 | * @uses WP_List_Table::get_sortable_columns() |
||
247 | * @uses Give_Update_Log_Table::get_pagenum() |
||
248 | * @uses Give_Update_Log_Table::get_logs() |
||
249 | * @uses Give_Update_Log_Table::get_log_count() |
||
250 | * |
||
251 | * @return void |
||
252 | */ |
||
253 | View Code Duplication | public function prepare_items() { |
|
268 | } |
||
269 |
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.