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 |
||
5 | class WooCommerce extends Module { |
||
6 | |||
7 | private $order_item_meta_whitelist = array( |
||
8 | // https://github.com/woocommerce/woocommerce/blob/master/includes/data-stores/class-wc-order-item-product-store.php#L20 |
||
9 | '_product_id', |
||
10 | '_variation_id', |
||
11 | '_qty', |
||
12 | // Tax ones also included in below class |
||
13 | // https://github.com/woocommerce/woocommerce/blob/master/includes/data-stores/class-wc-order-item-fee-data-store.php#L20 |
||
14 | '_tax_class', |
||
15 | '_tax_status', |
||
16 | '_line_subtotal', |
||
17 | '_line_subtotal_tax', |
||
18 | '_line_total', |
||
19 | '_line_tax', |
||
20 | '_line_tax_data', |
||
21 | // https://github.com/woocommerce/woocommerce/blob/master/includes/data-stores/class-wc-order-item-shipping-data-store.php#L20 |
||
22 | 'method_id', |
||
23 | 'cost', |
||
24 | 'total_tax', |
||
25 | 'taxes', |
||
26 | // https://github.com/woocommerce/woocommerce/blob/master/includes/data-stores/class-wc-order-item-tax-data-store.php#L20 |
||
27 | 'rate_id', |
||
28 | 'label', |
||
29 | 'compound', |
||
30 | 'tax_amount', |
||
31 | 'shipping_tax_amount', |
||
32 | // https://github.com/woocommerce/woocommerce/blob/master/includes/data-stores/class-wc-order-item-coupon-data-store.php |
||
33 | 'discount_amount', |
||
34 | 'discount_amount_tax', |
||
35 | ); |
||
36 | |||
37 | private $order_item_table_name; |
||
38 | |||
39 | public function __construct() { |
||
52 | |||
53 | function name() { |
||
56 | |||
57 | public function init_listeners( $callable ) { |
||
94 | |||
95 | public function init_full_sync_listeners( $callable ) { |
||
98 | |||
99 | public function get_full_sync_actions() { |
||
102 | |||
103 | public function init_before_send() { |
||
107 | |||
108 | public function filter_order_item( $args ) { |
||
113 | |||
114 | public function expand_order_item_ids( $args ) { |
||
130 | |||
131 | public function build_order_item( $order_item_id ) { |
||
135 | |||
136 | public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { |
||
141 | |||
142 | View Code Duplication | public function estimate_full_sync_actions( $config ) { |
|
150 | |||
151 | private function get_where_sql( $config ) { |
||
154 | |||
155 | public function add_woocommerce_options_whitelist( $list ) { |
||
158 | |||
159 | public function add_woocommerce_constants_whitelist( $list ) { |
||
162 | |||
163 | public function add_woocommerce_post_meta_whitelist( $list ) { |
||
166 | |||
167 | public function add_woocommerce_comment_meta_whitelist( $list ) { |
||
170 | |||
171 | private static $wc_options_whitelist = array( |
||
172 | 'woocommerce_currency', |
||
173 | 'woocommerce_db_version', |
||
174 | 'woocommerce_weight_unit', |
||
175 | 'woocommerce_version', |
||
176 | 'woocommerce_unforce_ssl_checkout', |
||
177 | 'woocommerce_tax_total_display', |
||
178 | 'woocommerce_tax_round_at_subtotal', |
||
179 | 'woocommerce_tax_display_shop', |
||
180 | 'woocommerce_tax_display_cart', |
||
181 | 'woocommerce_prices_include_tax', |
||
182 | 'woocommerce_price_thousand_sep', |
||
183 | 'woocommerce_price_num_decimals', |
||
184 | 'woocommerce_price_decimal_sep', |
||
185 | 'woocommerce_notify_low_stock', |
||
186 | 'woocommerce_notify_low_stock_amount', |
||
187 | 'woocommerce_notify_no_stock', |
||
188 | 'woocommerce_notify_no_stock_amount', |
||
189 | 'woocommerce_manage_stock', |
||
190 | 'woocommerce_force_ssl_checkout', |
||
191 | 'woocommerce_hide_out_of_stock_items', |
||
192 | 'woocommerce_file_download_method', |
||
193 | 'woocommerce_enable_signup_and_login_from_checkout', |
||
194 | 'woocommerce_enable_shipping_calc', |
||
195 | 'woocommerce_enable_review_rating', |
||
196 | 'woocommerce_enable_guest_checkout', |
||
197 | 'woocommerce_enable_coupons', |
||
198 | 'woocommerce_enable_checkout_login_reminder', |
||
199 | 'woocommerce_enable_ajax_add_to_cart', |
||
200 | 'woocommerce_dimension_unit', |
||
201 | 'woocommerce_default_country', |
||
202 | 'woocommerce_default_customer_address', |
||
203 | 'woocommerce_currency_pos', |
||
204 | 'woocommerce_api_enabled', |
||
205 | 'woocommerce_allow_tracking', |
||
206 | ); |
||
207 | |||
208 | private static $wc_constants_whitelist = array( |
||
209 | // woocommerce options |
||
210 | 'WC_PLUGIN_FILE', |
||
211 | 'WC_ABSPATH', |
||
212 | 'WC_PLUGIN_BASENAME', |
||
213 | 'WC_VERSION', |
||
214 | 'WOOCOMMERCE_VERSION', |
||
215 | 'WC_ROUNDING_PRECISION', |
||
216 | 'WC_DISCOUNT_ROUNDING_MODE', |
||
217 | 'WC_TAX_ROUNDING_MODE', |
||
218 | 'WC_DELIMITER', |
||
219 | 'WC_LOG_DIR', |
||
220 | 'WC_SESSION_CACHE_GROUP', |
||
221 | 'WC_TEMPLATE_DEBUG_MODE', |
||
222 | ); |
||
223 | |||
224 | private static $wc_post_meta_whitelist = array( |
||
225 | // woocommerce products |
||
226 | // https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-product-data-store-cpt.php#L21 |
||
227 | '_visibility', |
||
228 | '_sku', |
||
229 | '_price', |
||
230 | '_regular_price', |
||
231 | '_sale_price', |
||
232 | '_sale_price_dates_from', |
||
233 | '_sale_price_dates_to', |
||
234 | 'total_sales', |
||
235 | '_tax_status', |
||
236 | '_tax_class', |
||
237 | '_manage_stock', |
||
238 | '_backorders', |
||
239 | '_sold_individually', |
||
240 | '_weight', |
||
241 | '_length', |
||
242 | '_width', |
||
243 | '_height', |
||
244 | '_upsell_ids', |
||
245 | '_crosssell_ids', |
||
246 | '_purchase_note', |
||
247 | '_default_attributes', |
||
248 | '_product_attributes', |
||
249 | '_virtual', |
||
250 | '_downloadable', |
||
251 | '_download_limit', |
||
252 | '_download_expiry', |
||
253 | '_featured', |
||
254 | '_downloadable_files', |
||
255 | '_wc_rating_count', |
||
256 | '_wc_average_rating', |
||
257 | '_wc_review_count', |
||
258 | '_variation_description', |
||
259 | '_thumbnail_id', |
||
260 | '_file_paths', |
||
261 | '_product_image_gallery', |
||
262 | '_product_version', |
||
263 | '_wp_old_slug', |
||
264 | |||
265 | // woocommerce orders |
||
266 | // https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L27 |
||
267 | '_order_key', |
||
268 | '_order_currency', |
||
269 | // '_billing_first_name', do not sync these as they contain personal data |
||
270 | // '_billing_last_name', |
||
271 | // '_billing_company', |
||
272 | // '_billing_address_1', |
||
273 | // '_billing_address_2', |
||
274 | '_billing_city', |
||
275 | '_billing_state', |
||
276 | '_billing_postcode', |
||
277 | '_billing_country', |
||
278 | // '_billing_email', do not sync these as they contain personal data |
||
279 | // '_billing_phone', |
||
280 | // '_shipping_first_name', |
||
281 | // '_shipping_last_name', |
||
282 | // '_shipping_company', |
||
283 | // '_shipping_address_1', |
||
284 | // '_shipping_address_2', |
||
285 | '_shipping_city', |
||
286 | '_shipping_state', |
||
287 | '_shipping_postcode', |
||
288 | '_shipping_country', |
||
289 | '_completed_date', |
||
290 | '_paid_date', |
||
291 | '_cart_discount', |
||
292 | '_cart_discount_tax', |
||
293 | '_order_shipping', |
||
294 | '_order_shipping_tax', |
||
295 | '_order_tax', |
||
296 | '_order_total', |
||
297 | '_payment_method', |
||
298 | '_payment_method_title', |
||
299 | // '_transaction_id', do not sync these as they contain personal data |
||
300 | // '_customer_ip_address', |
||
301 | // '_customer_user_agent', |
||
302 | '_created_via', |
||
303 | '_order_version', |
||
304 | '_prices_include_tax', |
||
305 | '_date_completed', |
||
306 | '_date_paid', |
||
307 | '_payment_tokens', |
||
308 | '_billing_address_index', |
||
309 | '_shipping_address_index', |
||
310 | '_recorded_sales', |
||
311 | '_recorded_coupon_usage_counts', |
||
312 | // https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L539 |
||
313 | '_download_permissions_granted', |
||
314 | // https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L594 |
||
315 | '_order_stock_reduced', |
||
316 | |||
317 | // woocommerce order refunds |
||
318 | // https://github.com/woocommerce/woocommerce/blob/b8a2815ae546c836467008739e7ff5150cb08e93/includes/data-stores/class-wc-order-refund-data-store-cpt.php#L20 |
||
319 | '_order_currency', |
||
320 | '_refund_amount', |
||
321 | '_refunded_by', |
||
322 | '_refund_reason', |
||
323 | '_order_shipping', |
||
324 | '_order_shipping_tax', |
||
325 | '_order_tax', |
||
326 | '_order_total', |
||
327 | '_order_version', |
||
328 | '_prices_include_tax', |
||
329 | '_payment_tokens', |
||
330 | ); |
||
331 | |||
332 | private static $wc_comment_meta_whitelist = array( |
||
333 | 'rating', |
||
334 | ); |
||
335 | } |
||
336 |