From f6af54cb722259f2d43f807ccdcac36cdc3655e6 Mon Sep 17 00:00:00 2001 From: Aristeides Stathopoulos Date: Thu, 8 Sep 2016 00:33:34 +0300 Subject: [PATCH 1/8] no need for verbose-mode phpcs tests. --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 32233f8ff78..021e6679b1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,10 +50,10 @@ script: # -n flag: Do not print warnings. (shortcut for --warning-severity=0) # --standard: Use WordPress as the standard. # --extensions: Only sniff PHP files. - - /tmp/phpcs/scripts/phpcs -p -s -v -n ./*.php --standard=./phpcs.ruleset.xml --extensions=php - - /tmp/phpcs/scripts/phpcs -p -s -v -n ./**/*.php --standard=./phpcs.ruleset.xml --extensions=php --ignore=./vendor/*.php - - /tmp/phpcs/scripts/phpcs -p -s -v -n ./**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php --ignore=./vendor/**/*.php - - /tmp/phpcs/scripts/phpcs -p -s -v -n ./**/**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php --ignore=./vendor/**/**/*.php + - /tmp/phpcs/scripts/phpcs -p -s -n ./*.php --standard=./phpcs.ruleset.xml --extensions=php + - /tmp/phpcs/scripts/phpcs -p -s -n ./**/*.php --standard=./phpcs.ruleset.xml --extensions=php --ignore=./vendor/*.php + - /tmp/phpcs/scripts/phpcs -p -s -n ./**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php --ignore=./vendor/**/*.php + - /tmp/phpcs/scripts/phpcs -p -s -n ./**/**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php --ignore=./vendor/**/**/*.php after_script: - bash tests/bin/travis.sh after From b70f62bfa94b250dda0c13a237d87ed9ede8344e Mon Sep 17 00:00:00 2001 From: Aristeides Stathopoulos Date: Thu, 8 Sep 2016 00:34:39 +0300 Subject: [PATCH 2/8] Add 4th-level-deep tests --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 021e6679b1d..c56006d72a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,6 +54,7 @@ script: - /tmp/phpcs/scripts/phpcs -p -s -n ./**/*.php --standard=./phpcs.ruleset.xml --extensions=php --ignore=./vendor/*.php - /tmp/phpcs/scripts/phpcs -p -s -n ./**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php --ignore=./vendor/**/*.php - /tmp/phpcs/scripts/phpcs -p -s -n ./**/**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php --ignore=./vendor/**/**/*.php + - /tmp/phpcs/scripts/phpcs -p -s -n ./**/**/**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php --ignore=./vendor/**/**/*.php after_script: - bash tests/bin/travis.sh after From 734f284fa4fde5597913ee6aad1c06387348eea3 Mon Sep 17 00:00:00 2001 From: Aristeides Stathopoulos Date: Thu, 8 Sep 2016 01:32:24 +0300 Subject: [PATCH 3/8] WordPress.PHP.YodaConditions.NotYoda --- apigen/hook-docs.php | 14 +- includes/abstracts/abstract-wc-order.php | 2 +- includes/abstracts/abstract-wc-product.php | 32 ++-- .../abstracts/abstract-wc-settings-api.php | 8 +- .../abstracts/abstract-wc-shipping-method.php | 2 +- includes/admin/class-wc-admin-assets.php | 2 +- .../class-wc-admin-duplicate-product.php | 4 +- includes/admin/class-wc-admin-notices.php | 2 +- includes/admin/class-wc-admin-settings.php | 6 +- includes/class-wc-ajax.php | 8 +- includes/class-wc-cart.php | 18 +-- includes/class-wc-checkout.php | 8 +- includes/class-wc-countries.php | 4 +- includes/class-wc-customer.php | 2 +- includes/class-wc-form-handler.php | 2 +- includes/class-wc-geo-ip.php | 142 +++++++++--------- includes/class-wc-install.php | 4 +- includes/class-wc-legacy-api.php | 2 +- includes/class-wc-payment-gateways.php | 4 +- includes/class-wc-product-grouped.php | 4 +- includes/class-wc-product-variable.php | 12 +- includes/class-wc-product-variation.php | 4 +- includes/class-wc-query.php | 22 +-- includes/class-wc-shipping.php | 2 +- includes/class-wc-shortcodes.php | 6 +- includes/class-wc-tax.php | 27 ++-- includes/class-wc-tracker.php | 6 +- includes/wc-cart-functions.php | 4 +- includes/wc-conditional-functions.php | 2 +- includes/wc-core-functions.php | 4 +- includes/wc-deprecated-functions.php | 2 +- includes/wc-formatting-functions.php | 6 +- includes/wc-page-functions.php | 4 +- includes/wc-product-functions.php | 6 +- includes/wc-template-functions.php | 2 +- includes/wc-term-functions.php | 12 +- includes/wc-update-functions.php | 16 +- phpcs.ruleset.xml | 3 +- 38 files changed, 210 insertions(+), 200 deletions(-) diff --git a/apigen/hook-docs.php b/apigen/hook-docs.php index e03da4dd842..f65fd365572 100644 --- a/apigen/hook-docs.php +++ b/apigen/hook-docs.php @@ -12,9 +12,11 @@ class WC_HookFinder { private static function get_files( $pattern, $flags = 0, $path = '' ) { - if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) { + if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) { - if ( $dir == '\\' || $dir == '/' ) { $dir = ''; } // End IF Statement + if ( '\\' == $dir || '/' == $dir ) { + $dir = ''; + } return self::get_files( basename( $pattern ), $flags, $dir . '/' ); @@ -102,13 +104,13 @@ class WC_HookFinder { foreach ( $tokens as $index => $token ) { if ( is_array( $token ) ) { - if ( $token[0] == T_CLASS ) { + if ( T_CLASS == $token[0] ) { $token_type = 'class'; - } elseif ( $token[0] == T_FUNCTION ) { + } elseif ( T_FUNCTION == $token[0] ) { $token_type = 'function'; - } elseif ( $token[1] === 'do_action' ) { + } elseif ( 'do_action' === $token[1] ) { $token_type = 'action'; - } elseif ( $token[1] === 'apply_filters' ) { + } elseif ( 'apply_filters' === $token[1] ) { $token_type = 'filter'; } elseif ( $token_type && ! empty( trim( $token[1] ) ) ) { switch ( $token_type ) { diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index a417b88ce25..5b94393e036 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -1513,7 +1513,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { if ( $this->get_shipping_total() != 0 ) { - if ( $tax_display == 'excl' ) { + if ( 'excl' === $tax_display ) { // Show shipping excluding tax. $shipping = wc_price( $this->get_shipping_total(), array( 'currency' => $this->get_currency() ) ); diff --git a/includes/abstracts/abstract-wc-product.php b/includes/abstracts/abstract-wc-product.php index 85343f9e52a..dca58ae4d39 100644 --- a/includes/abstracts/abstract-wc-product.php +++ b/includes/abstracts/abstract-wc-product.php @@ -241,11 +241,11 @@ class WC_Product { */ public function check_stock_status() { if ( ! $this->backorders_allowed() && $this->get_total_stock() <= get_option( 'woocommerce_notify_no_stock_amount' ) ) { - if ( $this->stock_status !== 'outofstock' ) { + if ( 'outofstock' !== $this->stock_status ) { $this->set_stock_status( 'outofstock' ); } } elseif ( $this->backorders_allowed() || $this->get_total_stock() > get_option( 'woocommerce_notify_no_stock_amount' ) ) { - if ( $this->stock_status !== 'instock' ) { + if ( 'instock' !== $this->stock_status ) { $this->set_stock_status( 'instock' ); } } @@ -367,7 +367,7 @@ class WC_Product { * @return bool */ public function is_downloadable() { - return $this->downloadable == 'yes' ? true : false; + return ( 'yes' === $this->downloadable ); } /** @@ -464,7 +464,7 @@ class WC_Product { * @return bool */ public function is_virtual() { - return apply_filters( 'woocommerce_is_virtual', $this->virtual == 'yes' ? true : false, $this ); + return apply_filters( 'woocommerce_is_virtual', ( 'yes' === $this->virtual ), $this ); } /** @@ -599,7 +599,7 @@ class WC_Product { * @return bool */ public function managing_stock() { - return ( ! isset( $this->manage_stock ) || $this->manage_stock == 'no' || get_option( 'woocommerce_manage_stock' ) !== 'yes' ) ? false : true; + return ( ! isset( $this->manage_stock ) || 'no' === $this->manage_stock || 'yes' !== get_option( 'woocommerce_manage_stock' ) ) ? false : true; } /** @@ -608,7 +608,7 @@ class WC_Product { * @return bool */ public function is_in_stock() { - return apply_filters( 'woocommerce_product_is_in_stock', $this->stock_status === 'instock', $this ); + return apply_filters( 'woocommerce_product_is_in_stock', ( 'instock' === $this->stock_status ), $this ); } /** @@ -617,7 +617,7 @@ class WC_Product { * @return bool */ public function backorders_allowed() { - return apply_filters( 'woocommerce_product_backorders_allowed', $this->backorders === 'yes' || $this->backorders === 'notify' ? true : false, $this->id, $this ); + return apply_filters( 'woocommerce_product_backorders_allowed', ( 'yes' === $this->backorders || 'notify' === $this->backorders ), $this->id, $this ); } /** @@ -626,7 +626,7 @@ class WC_Product { * @return bool */ public function backorders_require_notification() { - return apply_filters( 'woocommerce_product_backorders_require_notification', $this->managing_stock() && $this->backorders === 'notify' ? true : false, $this ); + return apply_filters( 'woocommerce_product_backorders_require_notification', ( $this->managing_stock() && 'notify' === $this->backorders ), $this ); } /** @@ -731,7 +731,7 @@ class WC_Product { * @return bool */ public function is_featured() { - return $this->featured === 'yes' ? true : false; + return ( 'yes' === $this->featured ) ? true : false; } /** @@ -744,7 +744,7 @@ class WC_Product { $visible = false; // Published/private - } elseif ( $this->post->post_status !== 'publish' && ! current_user_can( 'edit_post', $this->id ) ) { + } elseif ( 'publish' !== $this->post->post_status && ! current_user_can( 'edit_post', $this->id ) ) { $visible = false; // Out of stock visibility @@ -794,7 +794,7 @@ class WC_Product { $purchasable = false; // Check the product is published - } elseif ( $this->post->post_status !== 'publish' && ! current_user_can( 'edit_post', $this->id ) ) { + } elseif ( 'publish' !== $this->post->post_status && ! current_user_can( 'edit_post', $this->id ) ) { $purchasable = false; } @@ -855,7 +855,7 @@ class WC_Product { */ public function get_price_including_tax( $qty = 1, $price = '' ) { - if ( $price === '' ) { + if ( '' === $price ) { $price = $this->get_price(); } @@ -913,7 +913,7 @@ class WC_Product { */ public function get_price_excluding_tax( $qty = 1, $price = '' ) { - if ( $price === '' ) { + if ( '' === $price ) { $price = $this->get_price(); } @@ -937,12 +937,12 @@ class WC_Product { */ public function get_display_price( $price = '', $qty = 1 ) { - if ( $price === '' ) { + if ( '' === $price ) { $price = $this->get_price(); } $tax_display_mode = get_option( 'woocommerce_tax_display_shop' ); - $display_price = $tax_display_mode == 'incl' ? $this->get_price_including_tax( $qty, $price ) : $this->get_price_excluding_tax( $qty, $price ); + $display_price = ( 'incl' === $tax_display_mode ) ? $this->get_price_including_tax( $qty, $price ) : $this->get_price_excluding_tax( $qty, $price ); return $display_price; } @@ -956,7 +956,7 @@ class WC_Product { */ public function get_price_suffix( $price = '', $qty = 1 ) { - if ( $price === '' ) { + if ( '' === $price ) { $price = $this->get_price(); } diff --git a/includes/abstracts/abstract-wc-settings-api.php b/includes/abstracts/abstract-wc-settings-api.php index ff62d47d936..66e6d484f0c 100644 --- a/includes/abstracts/abstract-wc-settings-api.php +++ b/includes/abstracts/abstract-wc-settings-api.php @@ -307,7 +307,7 @@ abstract class WC_Settings_API { * @return string */ public function get_tooltip_html( $data ) { - if ( $data['desc_tip'] === true ) { + if ( true === $data['desc_tip'] ) { $tip = $data['description']; } elseif ( ! empty( $data['desc_tip'] ) ) { $tip = $data['desc_tip']; @@ -325,7 +325,7 @@ abstract class WC_Settings_API { * @return string */ public function get_description_html( $data ) { - if ( $data['desc_tip'] === true ) { + if ( true === $data['desc_tip'] ) { $description = ''; } elseif ( ! empty( $data['desc_tip'] ) ) { $description = $data['description']; @@ -797,7 +797,7 @@ abstract class WC_Settings_API { */ public function validate_price_field( $key, $value ) { $value = is_null( $value ) ? '' : $value; - return $value === '' ? '' : wc_format_decimal( trim( stripslashes( $value ) ) ); + return ( '' === $value ) ? '' : wc_format_decimal( trim( stripslashes( $value ) ) ); } /** @@ -811,7 +811,7 @@ abstract class WC_Settings_API { */ public function validate_decimal_field( $key, $value ) { $value = is_null( $value ) ? '' : $value; - return $value === '' ? '' : wc_format_decimal( trim( stripslashes( $value ) ) ); + return ( '' === $value ) ? '' : wc_format_decimal( trim( stripslashes( $value ) ) ); } /** diff --git a/includes/abstracts/abstract-wc-shipping-method.php b/includes/abstracts/abstract-wc-shipping-method.php index 9dbff414c75..4c94f6fa198 100644 --- a/includes/abstracts/abstract-wc-shipping-method.php +++ b/includes/abstracts/abstract-wc-shipping-method.php @@ -253,7 +253,7 @@ abstract class WC_Shipping_Method extends WC_Settings_API { $taxes = $args['taxes']; // Taxes - if not an array and not set to false, calc tax based on cost and passed calc_tax variable. This saves shipping methods having to do complex tax calculations. - if ( ! is_array( $taxes ) && $taxes !== false && $total_cost > 0 && $this->is_taxable() ) { + if ( ! is_array( $taxes ) && false !== $taxes && $total_cost > 0 && $this->is_taxable() ) { $taxes = 'per_item' === $args['calc_tax'] ? $this->get_taxes_per_item( $args['cost'] ) : WC_Tax::calc_shipping_tax( $total_cost, WC_Tax::get_shipping_tax_rates() ); } diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php index 1f9ec9c6868..c4aaf9c5d2c 100644 --- a/includes/admin/class-wc-admin-assets.php +++ b/includes/admin/class-wc-admin-assets.php @@ -306,7 +306,7 @@ class WC_Admin_Assets { } // Product sorting - only when sorting by menu order on the products page - if ( current_user_can( 'edit_others_pages' ) && $screen_id == 'edit-product' && isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) { + if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) { wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION, true ); wp_enqueue_script( 'woocommerce_product_ordering' ); } diff --git a/includes/admin/class-wc-admin-duplicate-product.php b/includes/admin/class-wc-admin-duplicate-product.php index 1ce3d5c60c6..0c2bb653cc0 100644 --- a/includes/admin/class-wc-admin-duplicate-product.php +++ b/includes/admin/class-wc-admin-duplicate-product.php @@ -39,7 +39,7 @@ class WC_Admin_Duplicate_Product { return $actions; } - if ( $post->post_type != 'product' ) { + if ( 'product' !== $post->post_type ) { return $actions; } @@ -63,7 +63,7 @@ class WC_Admin_Duplicate_Product { return; } - if ( $post->post_type != 'product' ) { + if ( 'product' !== $post->post_type ) { return; } diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index f19816a3740..45020eb38f6 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -239,7 +239,7 @@ class WC_Admin_Notices { $theme_file = get_template_directory() . '/woocommerce/' . $file; } - if ( $theme_file !== false ) { + if ( false !== $theme_file ) { $core_version = WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file ); $theme_version = WC_Admin_Status::get_file_version( $theme_file ); diff --git a/includes/admin/class-wc-admin-settings.php b/includes/admin/class-wc-admin-settings.php index 7effb8e23f7..80788b724c6 100644 --- a/includes/admin/class-wc-admin-settings.php +++ b/includes/admin/class-wc-admin-settings.php @@ -206,7 +206,7 @@ class WC_Admin_Settings { $option_value = stripslashes( $option_value ); } - return $option_value === null ? $default : $option_value; + return ( null === $option_value ) ? $default : $option_value; } /** @@ -297,7 +297,7 @@ class WC_Admin_Settings { $type = $value['type']; $option_value = self::get_option( $value['id'], $value['default'] ); - if ( $value['type'] == 'color' ) { + if ( 'color' === $value['type'] ) { $type = 'text'; $value['class'] .= 'colorpick'; $description .= ''; @@ -366,7 +366,7 @@ class WC_Admin_Settings {