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 Jetpack_Sync_Module_WooCommerce extends Jetpack_Sync_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() { |
||
| 51 | |||
| 52 | function name() { |
||
| 55 | |||
| 56 | public function init_listeners( $callable ) { |
||
| 69 | |||
| 70 | public function init_full_sync_listeners( $callable ) { |
||
| 73 | |||
| 74 | public function get_full_sync_actions() { |
||
| 77 | |||
| 78 | public function init_before_send() { |
||
| 82 | |||
| 83 | public function filter_order_item( $args ) { |
||
| 87 | |||
| 88 | public function expand_order_item_ids( $args ) { |
||
| 104 | |||
| 105 | public function build_order_item( $order_item ) { |
||
| 120 | |||
| 121 | public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { |
||
| 126 | |||
| 127 | View Code Duplication | public function estimate_full_sync_actions( $config ) { |
|
| 135 | |||
| 136 | private function get_where_sql( $config ) { |
||
| 139 | |||
| 140 | public function add_woocommerce_options_whitelist( $list ) { |
||
| 143 | |||
| 144 | public function add_woocommerce_constants_whitelist( $list ) { |
||
| 147 | |||
| 148 | public function add_woocommerce_post_meta_whitelist( $list ) { |
||
| 151 | |||
| 152 | private static $wc_options_whitelist = array( |
||
| 153 | 'woocommerce_currency', |
||
| 154 | 'woocommerce_db_version', |
||
| 155 | 'woocommerce_weight_unit', |
||
| 156 | 'woocommerce_version', |
||
| 157 | 'woocommerce_unforce_ssl_checkout', |
||
| 158 | 'woocommerce_tax_total_display', |
||
| 159 | 'woocommerce_tax_round_at_subtotal', |
||
| 160 | 'woocommerce_tax_display_shop', |
||
| 161 | 'woocommerce_tax_display_cart', |
||
| 162 | 'woocommerce_prices_include_tax', |
||
| 163 | 'woocommerce_price_thousand_sep', |
||
| 164 | 'woocommerce_price_num_decimals', |
||
| 165 | 'woocommerce_price_decimal_sep', |
||
| 166 | 'woocommerce_notify_low_stock', |
||
| 167 | 'woocommerce_notify_low_stock_amount', |
||
| 168 | 'woocommerce_notify_no_stock', |
||
| 169 | 'woocommerce_notify_no_stock_amount', |
||
| 170 | 'woocommerce_manage_stock', |
||
| 171 | 'woocommerce_force_ssl_checkout', |
||
| 172 | 'woocommerce_hide_out_of_stock_items', |
||
| 173 | 'woocommerce_file_download_method', |
||
| 174 | 'woocommerce_enable_signup_and_login_from_checkout', |
||
| 175 | 'woocommerce_enable_shipping_calc', |
||
| 176 | 'woocommerce_enable_review_rating', |
||
| 177 | 'woocommerce_enable_guest_checkout', |
||
| 178 | 'woocommerce_enable_coupons', |
||
| 179 | 'woocommerce_enable_checkout_login_reminder', |
||
| 180 | 'woocommerce_enable_ajax_add_to_cart', |
||
| 181 | 'woocommerce_dimension_unit', |
||
| 182 | 'woocommerce_default_country', |
||
| 183 | 'woocommerce_default_customer_address', |
||
| 184 | 'woocommerce_currency_pos', |
||
| 185 | 'woocommerce_api_enabled', |
||
| 186 | 'woocommerce_allow_tracking', |
||
| 187 | ); |
||
| 188 | |||
| 189 | private static $wc_constants_whitelist = array( |
||
| 190 | //woocommerce options |
||
| 191 | 'WC_PLUGIN_FILE', |
||
| 192 | 'WC_ABSPATH', |
||
| 193 | 'WC_PLUGIN_BASENAME', |
||
| 194 | 'WC_VERSION', |
||
| 195 | 'WOOCOMMERCE_VERSION', |
||
| 196 | 'WC_ROUNDING_PRECISION', |
||
| 197 | 'WC_DISCOUNT_ROUNDING_MODE', |
||
| 198 | 'WC_TAX_ROUNDING_MODE', |
||
| 199 | 'WC_DELIMITER', |
||
| 200 | 'WC_LOG_DIR', |
||
| 201 | 'WC_SESSION_CACHE_GROUP', |
||
| 202 | 'WC_TEMPLATE_DEBUG_MODE', |
||
| 203 | ); |
||
| 204 | |||
| 205 | private static $wc_post_meta_whitelist = array( |
||
| 206 | //woocommerce products |
||
| 207 | '_stock_status', |
||
| 208 | '_visibility', |
||
| 209 | 'total_sales', |
||
| 210 | '_downloadable', |
||
| 211 | '_virtual', |
||
| 212 | '_regular_price', |
||
| 213 | '_sale_price', |
||
| 214 | '_tax_status', |
||
| 215 | '_tax_class', |
||
| 216 | '_featured', |
||
| 217 | '_price', |
||
| 218 | '_stock', |
||
| 219 | '_backorders', |
||
| 220 | '_manage_stock', |
||
| 221 | |||
| 222 | //woocommerce orders |
||
| 223 | '_order_currency', |
||
| 224 | '_prices_include_tax', |
||
| 225 | '_created_via', |
||
| 226 | '_billing_country', |
||
| 227 | '_billing_city', |
||
| 228 | '_billing_state', |
||
| 229 | '_billing_postcode', |
||
| 230 | '_shipping_country', |
||
| 231 | '_shipping_city', |
||
| 232 | '_shipping_state', |
||
| 233 | '_shipping_postcode', |
||
| 234 | '_payment_method', |
||
| 235 | '_payment_method_title', |
||
| 236 | '_order_shipping', |
||
| 237 | '_cart_discount', |
||
| 238 | '_cart_discount_tax', |
||
| 239 | '_order_tax', |
||
| 240 | '_order_shipping_tax', |
||
| 241 | '_order_total', |
||
| 242 | '_download_permissions_granted', |
||
| 243 | '_recorded_sales', |
||
| 244 | '_order_stock_reduced', |
||
| 245 | ); |
||
| 246 | } |
||
| 247 |