Commit 3d9b8d19ba9 for woocommerce

commit 3d9b8d19ba9834143882373b293a34eca7752d1f
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date:   Thu Sep 24 11:28:37 2026 +0300

    Fix PaymentUtils types that PHPStan reports (#68998)

    * Fix PaymentUtils type issues reported by PHPStan

    The token-ID callback documented its token as \WC_Token, a class that
    does not exist; it receives a WC_Payment_Token.
    get_saved_payment_methods() returned nothing for guests while
    documenting an array return, and passed a fourth argument to
    remove_filter(), which accepts three.

    Document the real token class, return null explicitly for guests and
    document it, and drop the extra argument. Behavior is unchanged, and
    the four matching PHPStan baseline entries are removed.

    * Add changelog entry for PaymentUtils type fixes

diff --git a/plugins/woocommerce/changelog/dev-payment-utils-phpstan-types b/plugins/woocommerce/changelog/dev-payment-utils-phpstan-types
new file mode 100644
index 00000000000..cb076a8a6a0
--- /dev/null
+++ b/plugins/woocommerce/changelog/dev-payment-utils-phpstan-types
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Fix PaymentUtils docblock and return types that PHPStan reports; no production change.
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index bb71ed432d4..d1cfdc8c228 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -69457,30 +69457,6 @@ parameters:
 			count: 1
 			path: src/StoreApi/Utilities/PaymentUtils.php

-		-
-			message: '#^Call to method get_id\(\) on an unknown class WC_Token\.$#'
-			identifier: class.notFound
-			count: 1
-			path: src/StoreApi/Utilities/PaymentUtils.php
-
-		-
-			message: '#^Function remove_filter invoked with 4 parameters, 2\-3 required\.$#'
-			identifier: arguments.count
-			count: 1
-			path: src/StoreApi/Utilities/PaymentUtils.php
-
-		-
-			message: '#^Method Automattic\\WooCommerce\\StoreApi\\Utilities\\PaymentUtils\:\:get_saved_payment_methods\(\) should return array but empty return statement found\.$#'
-			identifier: return.empty
-			count: 1
-			path: src/StoreApi/Utilities/PaymentUtils.php
-
-		-
-			message: '#^Parameter \$token of method Automattic\\WooCommerce\\StoreApi\\Utilities\\PaymentUtils\:\:include_token_id_with_payment_methods\(\) has invalid type WC_Token\.$#'
-			identifier: class.notFound
-			count: 1
-			path: src/StoreApi/Utilities/PaymentUtils.php
-
 		-
 			message: '#^Binary operation "/" between int\|string and \(float\|int\) results in an error\.$#'
 			identifier: binaryOp.invalid
diff --git a/plugins/woocommerce/src/StoreApi/Utilities/PaymentUtils.php b/plugins/woocommerce/src/StoreApi/Utilities/PaymentUtils.php
index f2021af919d..b6476e75171 100644
--- a/plugins/woocommerce/src/StoreApi/Utilities/PaymentUtils.php
+++ b/plugins/woocommerce/src/StoreApi/Utilities/PaymentUtils.php
@@ -14,8 +14,8 @@ class PaymentUtils {
 	 * Callback for woocommerce_payment_methods_list_item filter to add token id
 	 * to the generated list.
 	 *
-	 * @param array     $list_item The current list item for the saved payment method.
-	 * @param \WC_Token $token     The token for the current list item.
+	 * @param array             $list_item The current list item for the saved payment method.
+	 * @param \WC_Payment_Token $token     The token for the current list item.
 	 *
 	 * @return array The list item with the token id added.
 	 */
@@ -48,11 +48,11 @@ class PaymentUtils {
 	/**
 	 * Returns enabled saved payment methods for a customer and the default method if there are multiple.
 	 *
-	 * @return array
+	 * @return array|null Null when no customer is logged in.
 	 */
 	public static function get_saved_payment_methods() {
 		if ( ! is_user_logged_in() ) {
-			return;
+			return null;
 		}

 		add_filter( 'woocommerce_payment_methods_list_item', [ self::class, 'include_token_id_with_payment_methods' ], 10, 2 );
@@ -79,7 +79,7 @@ class PaymentUtils {
 			);
 		}

-		remove_filter( 'woocommerce_payment_methods_list_item', [ self::class, 'include_token_id_with_payment_methods' ], 10, 2 );
+		remove_filter( 'woocommerce_payment_methods_list_item', [ self::class, 'include_token_id_with_payment_methods' ], 10 );

 		return $payment_methods;
 	}