From faefc815c2741a64274801cece0fefcc0f9c0205 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Tue, 21 May 2024 15:32:56 +0200 Subject: [PATCH 01/19] avoid unnecessary recursion for the update_account_data method --- includes/class-wc-payments-account.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/includes/class-wc-payments-account.php b/includes/class-wc-payments-account.php index b3106527a2d..79b11b6646b 100644 --- a/includes/class-wc-payments-account.php +++ b/includes/class-wc-payments-account.php @@ -1675,7 +1675,7 @@ function () { * * @return void */ - public function update_cached_account_data( $property, $data ) { + public function update_account_data( $property, $data ) { $account_data = $this->database_cache->get( Database_Cache::ACCOUNT_KEY ); $account_data[ $property ] = is_array( $data ) ? array_merge( $account_data[ $property ] ?? [], $data ) : $data; @@ -1692,16 +1692,6 @@ public function refresh_account_data() { return $this->get_cached_account_data( true ); } - /** - * Updates the account data. - * - * @param string $property Property to update. - * @param mixed $data Data to update. - */ - public function update_account_data( $property, $data ) { - return $this->update_cached_account_data( $property, $data ); - } - /** * Checks if the cached account can be used in the current plugin state. * From e7aaf6c0ccafe6bbf2ac314bfa8b65156693ccca Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Tue, 21 May 2024 15:57:58 +0200 Subject: [PATCH 02/19] check for class existence before using it --- includes/class-wc-payments-payment-request-button-handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-payments-payment-request-button-handler.php b/includes/class-wc-payments-payment-request-button-handler.php index 7966c4ba45d..be4de29721e 100644 --- a/includes/class-wc-payments-payment-request-button-handler.php +++ b/includes/class-wc-payments-payment-request-button-handler.php @@ -343,7 +343,7 @@ public function get_product_price( $product, ?bool $is_deposit = null, int $depo } // If WooCommerce Deposits is active, we need to get the correct price for the product. - if ( class_exists( 'WC_Deposits_Product_Manager' ) && WC_Deposits_Product_Manager::deposits_enabled( $product->get_id() ) ) { + if ( class_exists( 'WC_Deposits_Product_Manager' ) && class_exists( 'WC_Deposits_Plans_Manager' ) && WC_Deposits_Product_Manager::deposits_enabled( $product->get_id() ) ) { // If is_deposit is null, we use the default deposit type for the product. if ( is_null( $is_deposit ) ) { $is_deposit = 'deposit' === WC_Deposits_Product_Manager::get_deposit_selected_type( $product->get_id() ); From 541f663e3d3141647cf007618c03e1d0e24dc47b Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Tue, 21 May 2024 17:06:39 +0200 Subject: [PATCH 03/19] [phpstan-ignore] ignore checks in Blocks_Data_Extractor --- includes/compat/blocks/class-blocks-data-extractor.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/compat/blocks/class-blocks-data-extractor.php b/includes/compat/blocks/class-blocks-data-extractor.php index c24e90649ce..673cae7f352 100644 --- a/includes/compat/blocks/class-blocks-data-extractor.php +++ b/includes/compat/blocks/class-blocks-data-extractor.php @@ -45,6 +45,7 @@ private function get_available_blocks() { // phpcs:ignore /** * @psalm-suppress UndefinedClass + * @phpstan-ignore-next-line */ $blocks[] = new \Automatewoo\Blocks\Marketing_Optin_Block(); } @@ -53,6 +54,7 @@ private function get_available_blocks() { // phpcs:ignore /** * @psalm-suppress UndefinedClass + * @phpstan-ignore-next-line */ $blocks[] = new \Mailchimp_Woocommerce_Newsletter_Blocks_Integration(); } @@ -96,11 +98,13 @@ private function get_mailpoet_data() { * We check whether relevant MailPoet classes exists before invoking this method. * * @psalm-suppress UndefinedClass + * @phpstan-ignore-next-line */ $mailpoet_wc_subscription = \MailPoet\DI\ContainerWrapper::getInstance()->get( \MailPoet\WooCommerce\Subscription::class ); // phpcs:ignore /** * @psalm-suppress UndefinedClass + * @phpstan-ignore-next-line */ $settings_instance = \MailPoet\Settings\SettingsController::getInstance(); $settings = [ From a31fcc4cfe5ba198473b250de5c1c8231706173f Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Thu, 23 May 2024 08:44:33 +0200 Subject: [PATCH 04/19] add class variable in WC_Payments_Email_Failed_Authentication_Retry --- ...class-wc-payments-email-failed-authentication-retry.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php b/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php index fb59585534f..b3a8c502312 100644 --- a/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php +++ b/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php @@ -18,6 +18,13 @@ */ class WC_Payments_Email_Failed_Authentication_Retry extends WC_Email_Failed_Order { + /** + * The details of the last retry (if any) recorded for a given order + * + * @var WCS_Retry + */ + private $retry; + /** * Constructor */ From 53a8480138b394241a7d48dfa9ca5ecbdab50b82 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Thu, 23 May 2024 12:17:58 +0200 Subject: [PATCH 05/19] replace the logger --- .../class-wc-payments-email-failed-authentication-retry.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php b/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php index b3a8c502312..582d2579bdd 100644 --- a/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php +++ b/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php @@ -9,6 +9,8 @@ * @package WooCommerce\Payments */ +use WCPay\Logger; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -78,7 +80,7 @@ public function trigger( $order_id, $order = null ) { $this->retry = WCS_Retry_Manager::store()->get_last_retry_for_order( wcs_get_objects_property( $order, 'id' ) ); $this->replace['retry-time'] = wcs_get_human_time_diff( $this->retry->get_time() ); } else { - WC_Stripe_Logger::log( 'WCS_Retry_Manager class or does not exist. Not able to send admin email about customer notification for authentication required for renewal payment.' ); + Logger::log( 'WCS_Retry_Manager class or does not exist. Not able to send admin email about customer notification for authentication required for renewal payment.' ); return; } From 21917c5d351a3294f0dd2274e34cfb32db91a450 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Thu, 23 May 2024 22:47:25 +0200 Subject: [PATCH 06/19] another round of fixes --- .../trait-wc-payment-gateway-wcpay-subscriptions.php | 10 +++++++++- includes/constants/class-base-constant.php | 2 ++ ...ass-wc-payments-express-checkout-button-handler.php | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php b/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php index 0351122186f..60428e024d1 100644 --- a/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php +++ b/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php @@ -103,6 +103,12 @@ abstract protected function prepare_payment_information( $order ); */ private static $has_attached_integration_hooks = false; + /** + * Used to temporary keep the state of the order_pay value on the Pay for order page with the SCA authorization flow. + * For more details, see remove_order_pay_var and restore_order_pay_var hooks. + */ + private $order_pay_var; + /** * Initialize subscription support and hooks. */ @@ -941,7 +947,9 @@ public function get_mandate_params_for_order( WC_Order $order ): array { if ( 1 < count( $subscriptions ) ) { $result['card']['mandate_options']['amount_type'] = 'maximum'; $result['card']['mandate_options']['interval'] = 'sporadic'; - unset( $result['card']['mandate_options']['interval_count'] ); + if (isset($result['card']['mandate_options']['interval_count'])) { + unset( $result['card']['mandate_options']['interval_count'] ); + } } return $result; diff --git a/includes/constants/class-base-constant.php b/includes/constants/class-base-constant.php index be1a5770922..c9f9dbf52c6 100644 --- a/includes/constants/class-base-constant.php +++ b/includes/constants/class-base-constant.php @@ -98,6 +98,8 @@ public static function search( string $value ) { */ public static function __callStatic( $name, $arguments ) { if ( ! isset( static::$object_cache[ $name ] ) ) { + // @phpstan-ignore-next-line + // The below line which uses new static( $name ) is essential to this method which creates instances of constants by their name. static::$object_cache[ $name ] = new static( $name ); } return static::$object_cache[ $name ]; diff --git a/includes/express-checkout/class-wc-payments-express-checkout-button-handler.php b/includes/express-checkout/class-wc-payments-express-checkout-button-handler.php index 9cf4ed5a71f..db7499d8b0b 100644 --- a/includes/express-checkout/class-wc-payments-express-checkout-button-handler.php +++ b/includes/express-checkout/class-wc-payments-express-checkout-button-handler.php @@ -476,7 +476,7 @@ public function get_product_price( $product, ?bool $is_deposit = null, int $depo } // If WooCommerce Deposits is active, we need to get the correct price for the product. - if ( class_exists( 'WC_Deposits_Product_Manager' ) && WC_Deposits_Product_Manager::deposits_enabled( $product->get_id() ) ) { + if ( class_exists( 'WC_Deposits_Product_Manager' ) && class_exists( 'WC_Deposits_Plans_Manager' ) && WC_Deposits_Product_Manager::deposits_enabled( $product->get_id() ) ) { if ( is_null( $is_deposit ) ) { /** * If is_deposit is null, we use the default deposit type for the product. From f96fc048c24b459ebb898fba738ffc822c405fbd Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Fri, 24 May 2024 09:48:11 +0200 Subject: [PATCH 07/19] ignore static class creation notice from PHPStan --- includes/constants/class-base-constant.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/constants/class-base-constant.php b/includes/constants/class-base-constant.php index c9f9dbf52c6..5cda5a771ce 100644 --- a/includes/constants/class-base-constant.php +++ b/includes/constants/class-base-constant.php @@ -98,8 +98,8 @@ public static function search( string $value ) { */ public static function __callStatic( $name, $arguments ) { if ( ! isset( static::$object_cache[ $name ] ) ) { - // @phpstan-ignore-next-line // The below line which uses new static( $name ) is essential to this method which creates instances of constants by their name. + // @phpstan-ignore-next-line. static::$object_cache[ $name ] = new static( $name ); } return static::$object_cache[ $name ]; From 88c928ca10a48822c7ea549b93abba0f72265a30 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Fri, 24 May 2024 10:03:11 +0200 Subject: [PATCH 08/19] over Name Your Price compatibility class by resolving PHPStan notices there --- .../Compatibility/WooCommerceNameYourPrice.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/multi-currency/Compatibility/WooCommerceNameYourPrice.php b/includes/multi-currency/Compatibility/WooCommerceNameYourPrice.php index 0095bc70559..155f99e1a4d 100644 --- a/includes/multi-currency/Compatibility/WooCommerceNameYourPrice.php +++ b/includes/multi-currency/Compatibility/WooCommerceNameYourPrice.php @@ -63,7 +63,7 @@ public function add_initial_currency( $cart_item, $product_id, $variation_id ) { $nyp_id = $variation_id ? $variation_id : $product_id; - if ( \WC_Name_Your_Price_Helpers::is_nyp( $nyp_id ) && isset( $cart_item['nyp'] ) ) { + if ( class_exists( '\WC_Name_Your_Price_Helpers' ) && \WC_Name_Your_Price_Helpers::is_nyp( $nyp_id ) && isset( $cart_item['nyp'] ) ) { $currency = $this->multi_currency->get_selected_currency(); $cart_item['nyp_currency'] = $currency->get_code(); $cart_item['nyp_original'] = $cart_item['nyp']; @@ -102,6 +102,7 @@ public function convert_cart_currency( $cart_item, $values ) { $cart_item['nyp'] = $this->multi_currency->get_raw_conversion( $raw_price, $selected_currency->get_code(), $from_currency ); } + // @phpstan-ignore-next-line. $cart_item = WC_Name_Your_Price()->cart->set_cart_item( $cart_item ); } @@ -130,7 +131,7 @@ public function should_convert_product_price( bool $return, $product ): bool { } // Check to see if the product is a NYP product. - if ( \WC_Name_Your_Price_Helpers::is_nyp( $product ) ) { + if ( class_exists( '\WC_Name_Your_Price_Helpers' ) && \WC_Name_Your_Price_Helpers::is_nyp( $product ) ) { return false; } From 0686b33fea2eebf2b6acfdf1e172ecc610e351f2 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Fri, 24 May 2024 10:09:00 +0200 Subject: [PATCH 09/19] product add-ons fixes --- .../WooCommerceProductAddOns.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/includes/multi-currency/Compatibility/WooCommerceProductAddOns.php b/includes/multi-currency/Compatibility/WooCommerceProductAddOns.php index f3e04db64fc..adc5cb9dabb 100644 --- a/includes/multi-currency/Compatibility/WooCommerceProductAddOns.php +++ b/includes/multi-currency/Compatibility/WooCommerceProductAddOns.php @@ -125,8 +125,10 @@ public function get_item_data( $addon_data, $addon, $cart_item ): array { // Quantity/multiplier add on needs to be split, calculated, then multiplied by input value. $price = $this->multi_currency->get_price( $addon['price'] / $addon['value'], 'product' ) * $addon['value']; } - $price = \WC_Product_Addons_Helper::get_product_addon_price_for_display( $price, $cart_item['data'] ); - $name .= ' (' . wc_price( $price ) . ')'; + if ( class_exists( '\WC_Product_Addons_Helper' ) ) { + $price = \WC_Product_Addons_Helper::get_product_addon_price_for_display( $price, $cart_item['data'] ); + $name .= ' (' . wc_price( $price ) . ')'; + } } else { // Get the percentage cost in the currency in use, and set the meta data on the product that the value was converted. $_product = wc_get_product( $cart_item['product_id'] ); @@ -245,12 +247,14 @@ public function order_line_item_meta( array $meta_data, array $addon, \WC_Order_ // Convert all others. $addon_price = $this->multi_currency->get_price( $addon['price'], 'product' ); } - $price = html_entity_decode( - wp_strip_all_tags( wc_price( \WC_Product_Addons_Helper::get_product_addon_price_for_display( $addon_price, $values['data'] ) ) ), - ENT_QUOTES, - get_bloginfo( 'charset' ) - ); - $addon['name'] .= ' (' . $price . ')'; + if ( class_exists( '\WC_Product_Addons_Helper' ) ) { + $price = html_entity_decode( + wp_strip_all_tags( wc_price( \WC_Product_Addons_Helper::get_product_addon_price_for_display( $addon_price, $values['data'] ) ) ), + ENT_QUOTES, + get_bloginfo( 'charset' ) + ); + $addon['name'] .= ' (' . $price . ')'; + } } if ( 'custom_price' === $addon['field_type'] ) { From c96082c513793e632c21d1c8d7b0cf8ac61bf475 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Fri, 24 May 2024 10:28:09 +0200 Subject: [PATCH 10/19] fix notices in WooPay package --- .../class-woopay-adapted-extensions.php | 25 +++++++++++-------- .../woopay/class-woopay-store-api-token.php | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/includes/woopay/class-woopay-adapted-extensions.php b/includes/woopay/class-woopay-adapted-extensions.php index bc5a4b37c96..2279e911314 100644 --- a/includes/woopay/class-woopay-adapted-extensions.php +++ b/includes/woopay/class-woopay-adapted-extensions.php @@ -171,7 +171,7 @@ public function get_extension_data() { ]; } - if ( $this->is_affiliate_for_woocommerce_enabled() ) { + if ( $this->is_affiliate_for_woocommerce_enabled() && function_exists( 'afwc_get_referrer_id' ) ) { /** * @psalm-suppress UndefinedFunction */ @@ -204,13 +204,15 @@ public function update_order_extension_data( $order_id ) { $this->is_affiliate_for_woocommerce_enabled() ) { $affiliate_id = (int) wc_clean( wp_unslash( $_GET['affiliate'] ) ); // phpcs:ignore WordPress.Security.NonceVerification - - // phpcs:ignore - /** - * @psalm-suppress UndefinedClass - */ - $affiliate_api = \AFWC_API::get_instance(); - $affiliate_api->track_conversion( $order_id, $affiliate_id, '', [ 'is_affiliate_eligible' => true ] ); + + if ( class_exists( '\AFWC_API' ) ) { + // phpcs:ignore + /** + * @psalm-suppress UndefinedClass + */ + $affiliate_api = \AFWC_API::get_instance(); + $affiliate_api->track_conversion( $order_id, $affiliate_id, '', [ 'is_affiliate_eligible' => true ] ); + } } } @@ -270,7 +272,10 @@ class_exists( '\AutomateWoo\Referrals\Referral_Manager' ) && * @return string|null */ private function get_automate_woo_advocate_id_from_cookie() { - $advocate_from_key_cookie = \AutomateWoo\Referrals\Referral_Manager::get_advocate_key_from_cookie(); - return $advocate_from_key_cookie ? $advocate_from_key_cookie->get_advocate_id() : null; + if ( class_exists( '\AutomateWoo\Referrals\Referral_Manager' ) ) { + $advocate_from_key_cookie = \AutomateWoo\Referrals\Referral_Manager::get_advocate_key_from_cookie(); + return $advocate_from_key_cookie ? $advocate_from_key_cookie->get_advocate_id() : null; + } + return null; } } diff --git a/includes/woopay/class-woopay-store-api-token.php b/includes/woopay/class-woopay-store-api-token.php index 0601b410350..b8dfb72a433 100644 --- a/includes/woopay/class-woopay-store-api-token.php +++ b/includes/woopay/class-woopay-store-api-token.php @@ -55,6 +55,7 @@ public function get_args() { * @psalm-suppress UndefinedMethod */ public function get_cart_token() { + // @phpstan-ignore-next-line. return parent::get_cart_token(); } } From d26ae4bb325269ef1a0a2fe062f6b0b567e7624e Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Fri, 24 May 2024 11:49:39 +0200 Subject: [PATCH 11/19] fix PHPStan errors in the newer src directory --- src/Internal/Payment/State/AbstractPaymentState.php | 11 +++++++---- src/Internal/Payment/State/StateFactory.php | 10 +++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Internal/Payment/State/AbstractPaymentState.php b/src/Internal/Payment/State/AbstractPaymentState.php index 19649b7eadb..6ae94c15b67 100644 --- a/src/Internal/Payment/State/AbstractPaymentState.php +++ b/src/Internal/Payment/State/AbstractPaymentState.php @@ -79,6 +79,7 @@ public function get_context(): PaymentContext { * @throws PaymentRequestException When data is not available or invalid. */ public function start_processing( PaymentRequest $request ) { + // @phpstan-ignore-next-line $this->throw_unavailable_method_exception( __METHOD__ ); } @@ -92,6 +93,7 @@ public function start_processing( PaymentRequest $request ) { * @throws StateTransitionException */ public function complete_processing() { + // @phpstan-ignore-next-line $this->throw_unavailable_method_exception( __METHOD__ ); } // phpcs:enable Squiz.Commenting.FunctionComment.InvalidNoReturn @@ -103,15 +105,15 @@ public function complete_processing() { * This method should only be called whenever the process is ready to transition * to the next state, as each new state will be considered the payment's latest one. * - * @template ConcreteState - * @param class-string | string $state_class The class of the state to crate. + * @template ConcreteState of AbstractPaymentState + * @param class-string $state_class The class of the state to create. * - * @return AbstractPaymentState | ConcreteState + * @return ConcreteState The generated payment state instance. * * @throws StateTransitionException In case the new state could not be created. * @throws ContainerException When the dependency container cannot instantiate the state. */ - protected function create_state( string $state_class ) { + protected function create_state( /*class-string*/ $state_class ): AbstractPaymentState { $state = $this->state_factory->create_state( $state_class, $this->context ); // This is where logging will be added. @@ -119,6 +121,7 @@ protected function create_state( string $state_class ) { return $state; } + /** * Throws an exception, indicating that a given method is not available. * diff --git a/src/Internal/Payment/State/StateFactory.php b/src/Internal/Payment/State/StateFactory.php index fa9554f4e73..7d0b77c375c 100644 --- a/src/Internal/Payment/State/StateFactory.php +++ b/src/Internal/Payment/State/StateFactory.php @@ -38,15 +38,15 @@ public function __construct( Container $container ) { /** * Creates a new state based on class name. * - * @template ConcreteState - * @param class-string | string $state_class Name of the state class. - * @param PaymentContext $context Context for the new state. + * @template ConcreteState of AbstractPaymentState + * @param class-string $state_class Name of the state class. + * @param PaymentContext $context Context for the new state. * - * @return AbstractPaymentState | ConcreteState The generated payment state instance. + * @return ConcreteState The generated payment state instance. * @throws ContainerException When the dependency container cannot instantiate the state. * @throws StateTransitionException When the class name is not a state. */ - public function create_state( string $state_class, PaymentContext $context ): AbstractPaymentState { + public function create_state( /*class-string*/ $state_class, PaymentContext $context ): AbstractPaymentState { if ( ! is_subclass_of( $state_class, AbstractPaymentState::class ) ) { throw new StateTransitionException( esc_html( From ceff2edfaa86cca23186349647ba4d2a9ee7c95d Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Fri, 24 May 2024 12:00:36 +0200 Subject: [PATCH 12/19] replace an inner named function with a static class method --- includes/class-wc-payments.php | 50 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/includes/class-wc-payments.php b/includes/class-wc-payments.php index 63e8b079157..ca0f6f8b01a 100644 --- a/includes/class-wc-payments.php +++ b/includes/class-wc-payments.php @@ -1434,37 +1434,37 @@ public static function add_woo_admin_notes() { } if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '7.5', '<' ) && get_woocommerce_currency() === 'NOK' ) { - /** - * Shows an alert notice for Norwegian merchants on WooCommerce 7.4 and below - */ - function wcpay_show_old_woocommerce_for_norway_notice() { - ?> -
-

- the plugins page.', 'woocommerce-payments' ), - 'WooCommerce', - 'WooPayments' - ), - [ - 'a1' => '', - ] - ) - ?> -

-
- + + Date: Fri, 24 May 2024 12:11:07 +0200 Subject: [PATCH 13/19] replace an inner named function with a static class method --- .../class-wc-payments-email-failed-authentication-retry.php | 2 +- .../trait-wc-payment-gateway-wcpay-subscriptions.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php b/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php index 582d2579bdd..7d4838bfceb 100644 --- a/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php +++ b/includes/compat/subscriptions/class-wc-payments-email-failed-authentication-retry.php @@ -22,7 +22,7 @@ class WC_Payments_Email_Failed_Authentication_Retry extends WC_Email_Failed_Orde /** * The details of the last retry (if any) recorded for a given order - * + * * @var WCS_Retry */ private $retry; diff --git a/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php b/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php index 60428e024d1..001dc3b8ffb 100644 --- a/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php +++ b/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php @@ -106,6 +106,8 @@ abstract protected function prepare_payment_information( $order ); /** * Used to temporary keep the state of the order_pay value on the Pay for order page with the SCA authorization flow. * For more details, see remove_order_pay_var and restore_order_pay_var hooks. + * + * @var string|int */ private $order_pay_var; @@ -947,7 +949,7 @@ public function get_mandate_params_for_order( WC_Order $order ): array { if ( 1 < count( $subscriptions ) ) { $result['card']['mandate_options']['amount_type'] = 'maximum'; $result['card']['mandate_options']['interval'] = 'sporadic'; - if (isset($result['card']['mandate_options']['interval_count'])) { + if ( isset( $result['card']['mandate_options']['interval_count'] ) ) { unset( $result['card']['mandate_options']['interval_count'] ); } } From 9a12f98aaf785b469d09a00f095cc2102be43ab9 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Fri, 24 May 2024 12:18:29 +0200 Subject: [PATCH 14/19] add changelog entry and small lint fixes --- changelog/fix-phpstan-errors | 4 ++++ .../trait-wc-payment-gateway-wcpay-subscriptions.php | 2 +- includes/woopay/class-woopay-adapted-extensions.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelog/fix-phpstan-errors diff --git a/changelog/fix-phpstan-errors b/changelog/fix-phpstan-errors new file mode 100644 index 00000000000..173e71e8d88 --- /dev/null +++ b/changelog/fix-phpstan-errors @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Fix PHPStan warnings. diff --git a/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php b/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php index 333b5e2aae7..da7a1379c14 100644 --- a/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php +++ b/includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php @@ -106,7 +106,7 @@ abstract protected function prepare_payment_information( $order ); /** * Used to temporary keep the state of the order_pay value on the Pay for order page with the SCA authorization flow. * For more details, see remove_order_pay_var and restore_order_pay_var hooks. - * + * * @var string|int */ private $order_pay_var; diff --git a/includes/woopay/class-woopay-adapted-extensions.php b/includes/woopay/class-woopay-adapted-extensions.php index 50a85046bcb..5b9c5c8643e 100644 --- a/includes/woopay/class-woopay-adapted-extensions.php +++ b/includes/woopay/class-woopay-adapted-extensions.php @@ -206,7 +206,7 @@ public function update_order_extension_data( $order_id ) { $this->is_affiliate_for_woocommerce_enabled() ) { $affiliate_id = (int) wc_clean( wp_unslash( $_GET['affiliate'] ) ); // phpcs:ignore WordPress.Security.NonceVerification - + if ( class_exists( '\AFWC_API' ) ) { // phpcs:ignore /** From 1bd87b04250beb143c2ca1060948da4c039a9133 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Fri, 24 May 2024 12:24:54 +0200 Subject: [PATCH 15/19] more linting fixes --- includes/class-wc-payments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-payments.php b/includes/class-wc-payments.php index ca0f6f8b01a..03fd5f515df 100644 --- a/includes/class-wc-payments.php +++ b/includes/class-wc-payments.php @@ -1434,7 +1434,7 @@ public static function add_woo_admin_notes() { } if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '7.5', '<' ) && get_woocommerce_currency() === 'NOK' ) { - add_filter( 'admin_notices', 'wcpay_show_old_woocommerce_for_norway_notice' ); + add_filter( 'admin_notices', [ __CLASS__, 'wcpay_show_old_woocommerce_for_norway_notice' ] ); } add_filter( 'admin_notices', [ __CLASS__, 'wcpay_show_old_woocommerce_for_hungary_sweden_and_czech_republic' ] ); From e0f96bf0d926e9413523da3c0de28eb3fc9e98f1 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Fri, 24 May 2024 16:04:14 +0200 Subject: [PATCH 16/19] misc --- includes/constants/class-base-constant.php | 2 +- src/Internal/Payment/State/AbstractPaymentState.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/constants/class-base-constant.php b/includes/constants/class-base-constant.php index 5cda5a771ce..876150b6581 100644 --- a/includes/constants/class-base-constant.php +++ b/includes/constants/class-base-constant.php @@ -98,7 +98,7 @@ public static function search( string $value ) { */ public static function __callStatic( $name, $arguments ) { if ( ! isset( static::$object_cache[ $name ] ) ) { - // The below line which uses new static( $name ) is essential to this method which creates instances of constants by their name. + // Instantiating constants by class name using the 'new static($name)' approach is integral to this method's functionality. // @phpstan-ignore-next-line. static::$object_cache[ $name ] = new static( $name ); } diff --git a/src/Internal/Payment/State/AbstractPaymentState.php b/src/Internal/Payment/State/AbstractPaymentState.php index 6ae94c15b67..942fec96ca2 100644 --- a/src/Internal/Payment/State/AbstractPaymentState.php +++ b/src/Internal/Payment/State/AbstractPaymentState.php @@ -121,7 +121,6 @@ protected function create_state( /*class-string*/ $state_class ): return $state; } - /** * Throws an exception, indicating that a given method is not available. * From 6eee3a6d3b1d69b0cf149b1de30adafc63cb1e5d Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Mon, 3 Jun 2024 10:19:10 +0200 Subject: [PATCH 17/19] update QIT docs --- tests/qit/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/qit/README.md b/tests/qit/README.md index a1d2e951709..87425097eec 100644 --- a/tests/qit/README.md +++ b/tests/qit/README.md @@ -1,18 +1,21 @@ ## WooCommerce Payments QIT tests -We currently only use the security tests from the [QIT toolkit](https://woocommerce.github.io/qit-documentation/#/) and these can be run locally. +We currently only use the security tests from the [QIT toolkit](https://qit.woo.com/docs/) and these can be run locally. #### Setup and running - Create `local.env` inside the `tests/qit/config/` directory by copying the variables from `default.env`. - To get the actual values for local config, refer to this [secret store](https://mc.a8c.com/secret-store/?secret_id=11043) link. - Once configured, the first time you run the `npm` command, it should create a local auth file which will be used for subsequent runs. -- For running, use: +- Currently, two types of tests are available through the `npm` command: Security Tests and PHPStan tests. PHPStan tests can also be run against the local development build. +- For running, use one of the following commands based on your requirements: ``` - npm run test:qit + npm run test:qit-security + npm run test:qit-phpstan + npm run test:qit-phpstan-local ``` -- The command uses the `build:release` command to create `woocommerce-payments.zip` at the root of the directory which is then uploaded and used for the QIT tests. +- The commands use the `build:release` to create `woocommerce-payments.zip` at the root of the directory which is then uploaded and used for the QIT tests. #### Analysing results From cec51f78c086f6d8ddcec569d7e64fba2157106f Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Mon, 3 Jun 2024 10:20:32 +0200 Subject: [PATCH 18/19] fix typo --- tests/qit/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qit/README.md b/tests/qit/README.md index 87425097eec..896cc9b0ab9 100644 --- a/tests/qit/README.md +++ b/tests/qit/README.md @@ -7,7 +7,7 @@ We currently only use the security tests from the [QIT toolkit](https://qit.woo. - To get the actual values for local config, refer to this [secret store](https://mc.a8c.com/secret-store/?secret_id=11043) link. - Once configured, the first time you run the `npm` command, it should create a local auth file which will be used for subsequent runs. -- Currently, two types of tests are available through the `npm` command: Security Tests and PHPStan tests. PHPStan tests can also be run against the local development build. +- Currently, two types of tests are available through the `npm` command: Security and PHPStan tests. PHPStan tests can also be run against the local development build. - For running, use one of the following commands based on your requirements: ``` npm run test:qit-security From 50b6290082cd5cc2947b91b50cd468ee7f776884 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Mon, 3 Jun 2024 16:58:09 +0200 Subject: [PATCH 19/19] resolve conflicts --- .../class-wc-payments-express-checkout-button-helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/express-checkout/class-wc-payments-express-checkout-button-helper.php b/includes/express-checkout/class-wc-payments-express-checkout-button-helper.php index 266e69e6f6d..401dc47a389 100644 --- a/includes/express-checkout/class-wc-payments-express-checkout-button-helper.php +++ b/includes/express-checkout/class-wc-payments-express-checkout-button-helper.php @@ -750,7 +750,7 @@ public function get_product_price( $product, ?bool $is_deposit = null, int $depo } // If WooCommerce Deposits is active, we need to get the correct price for the product. - if ( class_exists( 'WC_Deposits_Product_Manager' ) && WC_Deposits_Product_Manager::deposits_enabled( $product->get_id() ) ) { + if ( class_exists( 'WC_Deposits_Product_Manager' ) && class_exists( 'WC_Deposits_Plans_Manager' ) && WC_Deposits_Product_Manager::deposits_enabled( $product->get_id() ) ) { if ( is_null( $is_deposit ) ) { /** * If is_deposit is null, we use the default deposit type for the product.