Conditions | 16 |
Paths | 26 |
Total Lines | 106 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
37 | public static function status_tools() { |
||
38 | global $wpdb; |
||
39 | |||
40 | $tools = self::get_tools(); |
||
41 | |||
42 | if ( ! empty( $_GET['action'] ) && ! empty( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'debug_action' ) ) { |
||
43 | |||
44 | switch ( $_GET['action'] ) { |
||
45 | case 'clear_transients' : |
||
46 | wc_delete_product_transients(); |
||
47 | wc_delete_shop_order_transients(); |
||
48 | WC_Cache_Helper::get_transient_version( 'shipping', true ); |
||
49 | |||
50 | echo '<div class="updated inline"><p>' . __( 'Product Transients Cleared', 'woocommerce' ) . '</p></div>'; |
||
51 | break; |
||
52 | case 'clear_expired_transients' : |
||
53 | |||
54 | /* |
||
55 | * Deletes all expired transients. The multi-table delete syntax is used. |
||
56 | * to delete the transient record from table a, and the corresponding. |
||
57 | * transient_timeout record from table b. |
||
58 | * |
||
59 | * Based on code inside core's upgrade_network() function. |
||
60 | */ |
||
61 | $sql = "DELETE a, b FROM $wpdb->options a, $wpdb->options b |
||
62 | WHERE a.option_name LIKE %s |
||
63 | AND a.option_name NOT LIKE %s |
||
64 | AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) |
||
65 | AND b.option_value < %d"; |
||
66 | $rows = $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_transient_' ) . '%', $wpdb->esc_like( '_transient_timeout_' ) . '%', time() ) ); |
||
67 | |||
68 | $sql = "DELETE a, b FROM $wpdb->options a, $wpdb->options b |
||
69 | WHERE a.option_name LIKE %s |
||
70 | AND a.option_name NOT LIKE %s |
||
71 | AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) ) |
||
72 | AND b.option_value < %d"; |
||
73 | $rows2 = $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_site_transient_' ) . '%', $wpdb->esc_like( '_site_transient_timeout_' ) . '%', time() ) ); |
||
74 | |||
75 | echo '<div class="updated inline"><p>' . sprintf( __( '%d Transients Rows Cleared', 'woocommerce' ), $rows + $rows2 ) . '</p></div>'; |
||
76 | break; |
||
77 | case 'reset_roles' : |
||
78 | // Remove then re-add caps and roles |
||
79 | WC_Install::remove_roles(); |
||
80 | WC_Install::create_roles(); |
||
81 | |||
82 | echo '<div class="updated inline"><p>' . __( 'Roles successfully reset', 'woocommerce' ) . '</p></div>'; |
||
83 | break; |
||
84 | case 'recount_terms' : |
||
85 | |||
86 | $product_cats = get_terms( 'product_cat', array( 'hide_empty' => false, 'fields' => 'id=>parent' ) ); |
||
87 | |||
88 | _wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), true, false ); |
||
89 | |||
90 | $product_tags = get_terms( 'product_tag', array( 'hide_empty' => false, 'fields' => 'id=>parent' ) ); |
||
91 | |||
92 | _wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), true, false ); |
||
93 | |||
94 | echo '<div class="updated inline"><p>' . __( 'Terms successfully recounted', 'woocommerce' ) . '</p></div>'; |
||
95 | break; |
||
96 | case 'clear_sessions' : |
||
97 | |||
98 | $wpdb->query( "TRUNCATE {$wpdb->prefix}woocommerce_sessions" ); |
||
99 | |||
100 | wp_cache_flush(); |
||
101 | |||
102 | echo '<div class="updated inline"><p>' . __( 'Sessions successfully cleared', 'woocommerce' ) . '</p></div>'; |
||
103 | break; |
||
104 | case 'install_pages' : |
||
105 | WC_Install::create_pages(); |
||
106 | echo '<div class="updated inline"><p>' . __( 'All missing WooCommerce pages was installed successfully.', 'woocommerce' ) . '</p></div>'; |
||
107 | break; |
||
108 | case 'delete_taxes' : |
||
109 | |||
110 | $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;" ); |
||
111 | $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;" ); |
||
112 | WC_Cache_Helper::incr_cache_prefix( 'taxes' ); |
||
113 | |||
114 | echo '<div class="updated inline"><p>' . __( 'Tax rates successfully deleted', 'woocommerce' ) . '</p></div>'; |
||
115 | break; |
||
116 | case 'reset_tracking' : |
||
117 | delete_option( 'woocommerce_allow_tracking' ); |
||
118 | WC_Admin_Notices::add_notice( 'tracking' ); |
||
119 | |||
120 | echo '<div class="updated inline"><p>' . __( 'Usage tracking settings successfully reset.', 'woocommerce' ) . '</p></div>'; |
||
121 | break; |
||
122 | default : |
||
123 | $action = esc_attr( $_GET['action'] ); |
||
124 | if ( isset( $tools[ $action ]['callback'] ) ) { |
||
125 | $callback = $tools[ $action ]['callback']; |
||
126 | $return = call_user_func( $callback ); |
||
127 | if ( $return === false ) { |
||
128 | $callback_string = is_array( $callback ) ? get_class( $callback[0] ) . '::' . $callback[1] : $callback; |
||
129 | echo '<div class="error inline"><p>' . sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string ) . '</p></div>'; |
||
130 | } |
||
131 | } |
||
132 | break; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | // Display message if settings settings have been saved |
||
137 | if ( isset( $_REQUEST['settings-updated'] ) ) { |
||
138 | echo '<div class="updated inline"><p>' . __( 'Your changes have been saved.', 'woocommerce' ) . '</p></div>'; |
||
139 | } |
||
140 | |||
141 | include_once( 'views/html-admin-page-status-tools.php' ); |
||
142 | } |
||
143 | |||
346 |
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.