From 714c4c672eca10b9fb434fae571181cd8c9fcf0e Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 23 Aug 2017 14:21:42 +0100 Subject: [PATCH 1/7] unused prop --- includes/abstracts/abstract-wc-order.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index c0c4951cb94..5289f0ca525 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -1017,7 +1017,6 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { $coupons = $this->get_items( 'coupon' ); $coupon_code_to_id = wc_list_pluck( $coupons, 'get_id', 'get_code' ); $all_discounts = $discounts->get_discounts(); - $item_discounts = $discounts->get_discounts_by_item(); $coupon_discounts = $discounts->get_discounts_by_coupon(); if ( $coupon_discounts ) { From a7b697b679ea0bc50f7e06c4f838a54bcbb5016f Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 23 Aug 2017 14:25:41 +0100 Subject: [PATCH 2/7] type checks --- includes/abstracts/abstract-wc-order.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index 5289f0ca525..5922b475e03 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -890,17 +890,21 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { * Apply a coupon to the order and recalculate totals. * * @since 3.2.0 - * @param string|WC_Coupon $coupon Coupon code or object. + * @param string|WC_Coupon $raw_coupon Coupon code or object. * @return true|WP_Error True if applied, error if not. */ - public function apply_coupon( $coupon ) { - if ( ! is_a( $coupon, 'WC_Coupon' ) ) { - $code = wc_format_coupon_code( $coupon ); + public function apply_coupon( $raw_coupon ) { + if ( is_a( $raw_coupon, 'WC_Coupon' ) ) { + $coupon = $raw_coupon; + } elseif ( is_string( $raw_coupon ) ) { + $code = wc_format_coupon_code( $raw_coupon ); $coupon = new WC_Coupon( $code ); if ( $coupon->get_code() !== $code || ! $coupon->is_valid() ) { return new WP_Error( 'invalid_coupon', __( 'Invalid coupon code', 'woocommerce' ) ); } + } else { + return new WP_Error( 'invalid_coupon', __( 'Invalid coupon', 'woocommerce' ) ); } // Check to make sure coupon is not already applied. From c60859bf3c573ca42d3ea5bef8c2d684b0a6d295 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 23 Aug 2017 14:27:10 +0100 Subject: [PATCH 3/7] types --- includes/abstracts/abstract-wc-product.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/abstracts/abstract-wc-product.php b/includes/abstracts/abstract-wc-product.php index d754c752630..138c3735608 100644 --- a/includes/abstracts/abstract-wc-product.php +++ b/includes/abstracts/abstract-wc-product.php @@ -1190,7 +1190,7 @@ class WC_Product extends WC_Abstract_Legacy_Product { * Set download limit. * * @since 3.0.0 - * @param int $download_limit + * @param int|string $download_limit */ public function set_download_limit( $download_limit ) { $this->set_prop( 'download_limit', -1 === (int) $download_limit || '' === $download_limit ? -1 : absint( $download_limit ) ); @@ -1200,7 +1200,7 @@ class WC_Product extends WC_Abstract_Legacy_Product { * Set download expiry. * * @since 3.0.0 - * @param int $download_expiry + * @param int|string $download_limit */ public function set_download_expiry( $download_expiry ) { $this->set_prop( 'download_expiry', -1 === (int) $download_expiry || '' === $download_expiry ? -1 : absint( $download_expiry ) ); From 9483a7ec196bc5fbb6db0be3735032ebc014e06c Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 23 Aug 2017 14:27:30 +0100 Subject: [PATCH 4/7] invalid return --- includes/abstracts/abstract-wc-rest-controller.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/abstracts/abstract-wc-rest-controller.php b/includes/abstracts/abstract-wc-rest-controller.php index b06f5bddaec..b32f0c055d3 100644 --- a/includes/abstracts/abstract-wc-rest-controller.php +++ b/includes/abstracts/abstract-wc-rest-controller.php @@ -205,7 +205,6 @@ abstract class WC_REST_Controller extends WP_REST_Controller { public function validate_setting_text_field( $value, $setting ) { $value = is_null( $value ) ? '' : $value; return wp_kses_post( trim( stripslashes( $value ) ) ); - return $value; } /** From e0de3643bc18269dfd02155cc277623bdfaa092a Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 23 Aug 2017 14:28:25 +0100 Subject: [PATCH 5/7] ID is unused --- includes/abstracts/abstract-wc-rest-crud-controller.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/abstracts/abstract-wc-rest-crud-controller.php b/includes/abstracts/abstract-wc-rest-crud-controller.php index 05ef6317c39..cd663fe48ed 100644 --- a/includes/abstracts/abstract-wc-rest-crud-controller.php +++ b/includes/abstracts/abstract-wc-rest-crud-controller.php @@ -376,7 +376,6 @@ abstract class WC_REST_CRUD_Controller extends WC_REST_Posts_Controller { * @return WP_REST_Response|WP_Error */ public function delete_item( $request ) { - $id = (int) $request['id']; $force = (bool) $request['force']; $object = $this->get_object( (int) $request['id'] ); $result = false; From 2beddc59a7aeb8ace4c08a040480bd0b771eb5f8 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 23 Aug 2017 14:38:00 +0100 Subject: [PATCH 6/7] docblocks --- includes/abstracts/abstract-wc-rest-crud-controller.php | 2 +- includes/admin/class-wc-admin-addons.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/abstracts/abstract-wc-rest-crud-controller.php b/includes/abstracts/abstract-wc-rest-crud-controller.php index cd663fe48ed..ed4d5376d7f 100644 --- a/includes/abstracts/abstract-wc-rest-crud-controller.php +++ b/includes/abstracts/abstract-wc-rest-crud-controller.php @@ -37,7 +37,7 @@ abstract class WC_REST_CRUD_Controller extends WC_REST_Posts_Controller { * Get object. * * @param int $id Object ID. - * @return WP_Error|WC_Data + * @return object WC_Data object or WP_Error object. */ protected function get_object( $id ) { return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); diff --git a/includes/admin/class-wc-admin-addons.php b/includes/admin/class-wc-admin-addons.php index 43562bbf94a..347ea1c1820 100644 --- a/includes/admin/class-wc-admin-addons.php +++ b/includes/admin/class-wc-admin-addons.php @@ -477,6 +477,15 @@ class WC_Admin_Addons { $theme = wp_get_theme(); $section_keys = array_keys( $sections ); $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); + + /** + * Addon page view. + * + * @uses $sections + * @uses $theme + * @uses $section_keys + * @uses $current_section + */ include_once( dirname( __FILE__ ) . '/views/html-admin-page-addons.php' ); } From 9d877a3b3425681702b9cb66e22b6162b9f448cf Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 23 Aug 2017 14:40:34 +0100 Subject: [PATCH 7/7] Unused vars --- includes/admin/helper/class-wc-helper-api.php | 2 +- includes/admin/helper/class-wc-helper-plugin-info.php | 1 - includes/admin/helper/class-wc-helper.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/admin/helper/class-wc-helper-api.php b/includes/admin/helper/class-wc-helper-api.php index 646c814c724..014b693d4b3 100644 --- a/includes/admin/helper/class-wc-helper-api.php +++ b/includes/admin/helper/class-wc-helper-api.php @@ -66,7 +66,7 @@ class WC_Helper_API { $request_uri = parse_url( $url, PHP_URL_PATH ); $query_string = parse_url( $url, PHP_URL_QUERY ); - if ( $query_string ) { + if ( is_string( $query_string ) ) { $request_uri .= '?' . $query_string; } diff --git a/includes/admin/helper/class-wc-helper-plugin-info.php b/includes/admin/helper/class-wc-helper-plugin-info.php index 033ec8c0b3e..351c92c54d5 100644 --- a/includes/admin/helper/class-wc-helper-plugin-info.php +++ b/includes/admin/helper/class-wc-helper-plugin-info.php @@ -40,7 +40,6 @@ class WC_Helper_Plugin_Info { // Look through local Woo plugins by slugs. foreach ( WC_Helper::get_local_woo_plugins() as $plugin ) { - $slug = dirname( $plugin['_filename'] ); if ( dirname( $plugin['_filename'] ) === $args->slug ) { $plugin['_slug'] = $args->slug; $found_plugin = $plugin; diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index 8a997353dc3..e5f8c6e626e 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -615,7 +615,7 @@ class WC_Helper { 'wc-helper-status' => 'helper-disconnected', ), admin_url( 'admin.php' ) ); - $result = WC_Helper_API::post( 'oauth/invalidate_token', array( + WC_Helper_API::post( 'oauth/invalidate_token', array( 'authenticated' => true, ) );