Conditions | 5 |
Paths | 6 |
Total Lines | 72 |
Code Lines | 55 |
Lines | 14 |
Ratio | 19.44 % |
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 |
||
122 | public function output_tax_rates() { |
||
123 | global $wpdb, $current_section; |
||
124 | |||
125 | $current_class = $this->get_current_tax_class(); |
||
126 | |||
127 | $countries = array(); |
||
128 | View Code Duplication | foreach ( WC()->countries->get_allowed_countries() as $value => $label ) { |
|
|
|||
129 | $countries[] = array( |
||
130 | 'value' => $value, |
||
131 | 'label' => esc_js( html_entity_decode( $label ) ), |
||
132 | ); |
||
133 | } |
||
134 | |||
135 | $states = array(); |
||
136 | View Code Duplication | foreach ( WC()->countries->get_allowed_country_states() as $label ) { |
|
137 | foreach ( $label as $code => $state ) { |
||
138 | $states[] = array( |
||
139 | 'value' => $code, |
||
140 | 'label' => esc_js( html_entity_decode( $state ) ), |
||
141 | ); |
||
142 | } |
||
143 | } |
||
144 | |||
145 | $base_url = admin_url( add_query_arg( array( |
||
146 | 'page' => 'wc-settings', |
||
147 | 'tab' => 'tax', |
||
148 | 'section' => $current_section, |
||
149 | ), 'admin.php' ) ); |
||
150 | |||
151 | // Localize and enqueue our js. |
||
152 | wp_localize_script( 'wc-settings-tax', 'htmlSettingsTaxLocalizeScript', array( |
||
153 | 'current_class' => $current_class, |
||
154 | 'wc_tax_nonce' => wp_create_nonce( 'wc_tax_nonce-class:' . $current_class ), |
||
155 | 'base_url' => $base_url, |
||
156 | 'rates' => array_values( WC_Tax::get_rates_for_tax_class( $current_class ) ), |
||
157 | 'page' => ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1, |
||
158 | 'limit' => 100, |
||
159 | 'countries' => $countries, |
||
160 | 'states' => $states, |
||
161 | 'default_rate' => array( |
||
162 | 'tax_rate_id' => 0, |
||
163 | 'tax_rate_country' => '', |
||
164 | 'tax_rate_state' => '', |
||
165 | 'tax_rate' => '', |
||
166 | 'tax_rate_name' => '', |
||
167 | 'tax_rate_priority' => 1, |
||
168 | 'tax_rate_compound' => 0, |
||
169 | 'tax_rate_shipping' => 1, |
||
170 | 'tax_rate_order' => null, |
||
171 | 'tax_rate_class' => $current_class, |
||
172 | ), |
||
173 | 'strings' => array( |
||
174 | 'no_rows_selected' => __( 'No row(s) selected', 'woocommerce' ), |
||
175 | 'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ), |
||
176 | 'csv_data_cols' => array( |
||
177 | __( 'Country Code', 'woocommerce' ), |
||
178 | __( 'State Code', 'woocommerce' ), |
||
179 | __( 'ZIP/Postcode', 'woocommerce' ), |
||
180 | __( 'City', 'woocommerce' ), |
||
181 | __( 'Rate %', 'woocommerce' ), |
||
182 | __( 'Tax Name', 'woocommerce' ), |
||
183 | __( 'Priority', 'woocommerce' ), |
||
184 | __( 'Compound', 'woocommerce' ), |
||
185 | __( 'Shipping', 'woocommerce' ), |
||
186 | __( 'Tax Class', 'woocommerce' ), |
||
187 | ), |
||
188 | ), |
||
189 | ) ); |
||
190 | wp_enqueue_script( 'wc-settings-tax' ); |
||
191 | |||
192 | include( 'views/html-settings-tax.php' ); |
||
193 | } |
||
194 | |||
290 |
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.