| Conditions | 21 |
| Paths | 38 |
| Total Lines | 109 |
| Code Lines | 93 |
| 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 |
||
| 247 | private static function get_script_data( $handle ) { |
||
| 248 | global $wp; |
||
| 249 | |||
| 250 | switch ( $handle ) { |
||
| 251 | case 'woocommerce' : |
||
| 252 | return array( |
||
| 253 | 'ajax_url' => WC()->ajax_url(), |
||
| 254 | 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ) |
||
| 255 | ); |
||
| 256 | break; |
||
|
|
|||
| 257 | case 'wc-geolocation' : |
||
| 258 | return array( |
||
| 259 | 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ), |
||
| 260 | 'home_url' => home_url(), |
||
| 261 | 'is_available' => ! ( is_cart() || is_account_page() || is_checkout() || is_customize_preview() ) ? '1' : '0', |
||
| 262 | 'hash' => isset( $_GET['v'] ) ? wc_clean( $_GET['v'] ) : '' |
||
| 263 | ); |
||
| 264 | break; |
||
| 265 | case 'wc-single-product' : |
||
| 266 | return array( |
||
| 267 | 'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ), |
||
| 268 | 'review_rating_required' => get_option( 'woocommerce_review_rating_required' ), |
||
| 269 | ); |
||
| 270 | break; |
||
| 271 | case 'wc-checkout' : |
||
| 272 | return array( |
||
| 273 | 'ajax_url' => WC()->ajax_url(), |
||
| 274 | 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ), |
||
| 275 | 'update_order_review_nonce' => wp_create_nonce( 'update-order-review' ), |
||
| 276 | 'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ), |
||
| 277 | 'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ), |
||
| 278 | 'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ), |
||
| 279 | 'checkout_url' => WC_AJAX::get_endpoint( "checkout" ), |
||
| 280 | 'is_checkout' => is_page( wc_get_page_id( 'checkout' ) ) && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ? 1 : 0, |
||
| 281 | 'debug_mode' => defined('WP_DEBUG') && WP_DEBUG, |
||
| 282 | 'i18n_checkout_error' => esc_attr__( 'Error processing checkout. Please try again.', 'woocommerce' ), |
||
| 283 | ); |
||
| 284 | break; |
||
| 285 | case 'wc-address-i18n' : |
||
| 286 | return array( |
||
| 287 | 'locale' => json_encode( WC()->countries->get_country_locale() ), |
||
| 288 | 'locale_fields' => json_encode( WC()->countries->get_country_locale_field_selectors() ), |
||
| 289 | 'i18n_required_text' => esc_attr__( 'required', 'woocommerce' ), |
||
| 290 | ); |
||
| 291 | break; |
||
| 292 | case 'wc-cart' : |
||
| 293 | return array( |
||
| 294 | 'ajax_url' => WC()->ajax_url(), |
||
| 295 | 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ), |
||
| 296 | 'update_shipping_method_nonce' => wp_create_nonce( "update-shipping-method" ), |
||
| 297 | 'apply_coupon_nonce' => wp_create_nonce( "apply-coupon" ), |
||
| 298 | 'remove_coupon_nonce' => wp_create_nonce( "remove-coupon" ), |
||
| 299 | ); |
||
| 300 | break; |
||
| 301 | case 'wc-cart-fragments' : |
||
| 302 | return array( |
||
| 303 | 'ajax_url' => WC()->ajax_url(), |
||
| 304 | 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ), |
||
| 305 | 'fragment_name' => apply_filters( 'woocommerce_cart_fragment_name', 'wc_fragments' ) |
||
| 306 | ); |
||
| 307 | break; |
||
| 308 | case 'wc-add-to-cart' : |
||
| 309 | return array( |
||
| 310 | 'ajax_url' => WC()->ajax_url(), |
||
| 311 | 'wc_ajax_url' => WC_AJAX::get_endpoint( "%%endpoint%%" ), |
||
| 312 | 'i18n_view_cart' => esc_attr__( 'View Cart', 'woocommerce' ), |
||
| 313 | 'cart_url' => apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url() ), |
||
| 314 | 'is_cart' => is_cart(), |
||
| 315 | 'cart_redirect_after_add' => get_option( 'woocommerce_cart_redirect_after_add' ) |
||
| 316 | ); |
||
| 317 | break; |
||
| 318 | case 'wc-add-to-cart-variation' : |
||
| 319 | // We also need the wp.template for this script :) |
||
| 320 | wc_get_template( 'single-product/add-to-cart/variation.php' ); |
||
| 321 | |||
| 322 | return array( |
||
| 323 | 'i18n_no_matching_variations_text' => esc_attr__( 'Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce' ), |
||
| 324 | 'i18n_make_a_selection_text' => esc_attr__( 'Please select some product options before adding this product to your cart.', 'woocommerce' ), |
||
| 325 | 'i18n_unavailable_text' => esc_attr__( 'Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce' ) |
||
| 326 | ); |
||
| 327 | break; |
||
| 328 | case 'wc-country-select' : |
||
| 329 | return array( |
||
| 330 | 'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ), |
||
| 331 | 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ), |
||
| 332 | 'i18n_matches_1' => _x( 'One result is available, press enter to select it.', 'enhanced select', 'woocommerce' ), |
||
| 333 | 'i18n_matches_n' => _x( '%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce' ), |
||
| 334 | 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ), |
||
| 335 | 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ), |
||
| 336 | 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ), |
||
| 337 | 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ), |
||
| 338 | 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ), |
||
| 339 | 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ), |
||
| 340 | 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ), |
||
| 341 | 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ), |
||
| 342 | 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce' ), |
||
| 343 | 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce' ), |
||
| 344 | ); |
||
| 345 | break; |
||
| 346 | case 'wc-password-strength-meter' : |
||
| 347 | return array( |
||
| 348 | 'min_password_strength' => apply_filters( 'woocommerce_min_password_strength', 3 ), |
||
| 349 | 'i18n_password_error' => esc_attr__( 'Please enter a stronger password.', 'woocommerce' ), |
||
| 350 | 'i18n_password_hint' => esc_attr__( 'The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).', 'woocommerce' ) |
||
| 351 | ); |
||
| 352 | break; |
||
| 353 | } |
||
| 354 | return false; |
||
| 355 | } |
||
| 356 | |||
| 368 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.