From 90d27c65dabd918ac40488390166afe4642e0a35 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Wed, 7 Mar 2018 15:29:36 -0300 Subject: [PATCH] Fix phpcs violations in includes/shipping/legacy-free-shipping/class-wc-shipping-legacy-free-shipping.php --- ...class-wc-shipping-legacy-free-shipping.php | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/includes/shipping/legacy-free-shipping/class-wc-shipping-legacy-free-shipping.php b/includes/shipping/legacy-free-shipping/class-wc-shipping-legacy-free-shipping.php index 547cd88b998..55c4ebde1fc 100644 --- a/includes/shipping/legacy-free-shipping/class-wc-shipping-legacy-free-shipping.php +++ b/includes/shipping/legacy-free-shipping/class-wc-shipping-legacy-free-shipping.php @@ -1,7 +1,12 @@ id = 'legacy_free_shipping'; - $this->method_title = __( 'Free shipping (legacy)', 'woocommerce' ); + $this->id = 'legacy_free_shipping'; + $this->method_title = __( 'Free shipping (legacy)', 'woocommerce' ); + /* translators: %s: Admin shipping settings URL */ $this->method_description = '' . sprintf( __( 'This method is deprecated in 2.6.0 and will be removed in future versions - we recommend disabling it and instead setting up a new rate within your Shipping zones.', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ) . ''; $this->init(); } @@ -51,11 +64,11 @@ class WC_Shipping_Legacy_Free_Shipping extends WC_Shipping_Method { * @return string */ public function get_option_key() { - return $this->plugin_id . 'free_shipping' . '_settings'; + return $this->plugin_id . 'free_shipping_settings'; } /** - * init function. + * Init function. */ public function init() { @@ -63,7 +76,7 @@ class WC_Shipping_Legacy_Free_Shipping extends WC_Shipping_Method { $this->init_form_fields(); $this->init_settings(); - // Define user set variables + // Define user set variables. $this->enabled = $this->get_option( 'enabled' ); $this->title = $this->get_option( 'title' ); $this->min_amount = $this->get_option( 'min_amount', 0 ); @@ -71,7 +84,7 @@ class WC_Shipping_Legacy_Free_Shipping extends WC_Shipping_Method { $this->countries = $this->get_option( 'countries' ); $this->requires = $this->get_option( 'requires' ); - // Actions + // Actions. add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); } @@ -139,34 +152,35 @@ class WC_Shipping_Legacy_Free_Shipping extends WC_Shipping_Method { } /** - * is_available function. + * Check if package is available. * - * @param array $package + * @param array $package Package information. * @return bool */ public function is_available( $package ) { - if ( 'no' == $this->enabled ) { + if ( 'no' === $this->enabled ) { return false; } - if ( 'specific' == $this->availability ) { + if ( 'specific' === $this->availability ) { $ship_to_countries = $this->countries; } else { $ship_to_countries = array_keys( WC()->countries->get_shipping_countries() ); } - if ( is_array( $ship_to_countries ) && ! in_array( $package['destination']['country'], $ship_to_countries ) ) { + if ( is_array( $ship_to_countries ) && ! in_array( $package['destination']['country'], $ship_to_countries, true ) ) { return false; } - // Enabled logic + // Enabled logic. $is_available = false; $has_coupon = false; $has_met_min_amount = false; - if ( in_array( $this->requires, array( 'coupon', 'either', 'both' ) ) ) { + if ( in_array( $this->requires, array( 'coupon', 'either', 'both' ), true ) ) { + $coupons = WC()->cart->get_coupons(); - if ( $coupons = WC()->cart->get_coupons() ) { + if ( $coupons ) { foreach ( $coupons as $code => $coupon ) { if ( $coupon->is_valid() && $coupon->get_free_shipping() ) { $has_coupon = true; @@ -175,7 +189,7 @@ class WC_Shipping_Legacy_Free_Shipping extends WC_Shipping_Method { } } - if ( in_array( $this->requires, array( 'min_amount', 'either', 'both' ) ) ) { + if ( in_array( $this->requires, array( 'min_amount', 'either', 'both' ), true ) ) { $total = WC()->cart->get_displayed_subtotal(); if ( WC()->cart->display_prices_including_tax() ) { @@ -219,7 +233,9 @@ class WC_Shipping_Legacy_Free_Shipping extends WC_Shipping_Method { } /** - * calculate_shipping function. + * Calculate shipping. + * + * @param array $package Package information. */ public function calculate_shipping( $package = array() ) { $args = array(