Commit 127b922b523 for woocommerce

commit 127b922b5232f89e895619d745dba3ae49f42ccf
Author: Rostislav Wolný <1082140+costasovo@users.noreply.github.com>
Date:   Tue Dec 1 14:07:59 2026 +0100

    Improve PHPStan types for calls through WC_Data_Store (#71129)

    * Let PHPStan see methods WC_Data_Store forwards to the store it wraps

    WC_Data_Store passes calls it does not define on to the store it wraps, through __call(). PHPStan cannot follow that, so it reported every such call as an undefined method: over a hundred baseline entries and a growing number of @phpstan-ignore comments, which also hid real type errors at those calls. A @mixin on the wrapped store, and a load() return type picked from a map of the default store classes, let PHPStan check these calls. The map describes the default stores; filters can still replace a store at runtime. With the calls visible, PHPStan reports 30 errors that the baseline does not cover. The following commits fix them, grouped by kind.

    * Add a PHPStan extension for WC_Data_Store::has_callable()

    Some data store methods are optional: the core stores have them, but a store from another plugin may not, so callers check has_callable() before calling them. PHPStan did not know that the check makes the call safe, so each such call needed a @phpstan-ignore comment. The extension treats a true has_callable( 'name' ) like method_exists(). That removes those comments and fixes the get_orders_type() error from the previous commit, while a call to an optional method without the check is still reported.

    * Fix data store docblocks that do not match the code

    Once PHPStan reads data store docblocks at every call site, many turn out not to match what the methods do. Methods that return a database row said object, so reading a property from the result was an error; the row is a stdClass, or null when nothing is found. get_zone_id_from_package() said its package is an object but reads it as an array. Other parameter types were narrower than what callers pass and the method accepts. search_webhooks() and the stock notifications query() return a different shape depending on one argument, so they get a conditional return type. This fixes 22 of the 30 errors from the first commit. The narrower query() type also turns an existing baseline entry for the stock notifications list pagination into a more precise error, fixed in a later commit. Docblocks only; nothing changes at runtime.

    * Fix fatal errors when a product or stock notification cannot be loaded

    wc_update_product_stock() loads the product that manages the stock, which is the parent for some variations, and called methods on it without checking that it loaded. When it cannot be loaded, the function now returns false, as it already does when the product itself cannot be loaded, instead of failing with a fatal error. The stock notifications admin did the same with notifications: deleting, enabling or cancelling one that no longer exists, for example from a stale page, called methods on false. That throws an Error, which the existing catch block for Exception does not catch. Missing notifications are now skipped, or reported as not found. The list table's data store property is now documented as the WC_Data_Store wrapper it holds, which is what let PHPStan see these calls. Includes a test for the stock case.

    * Fix fatal errors when a product or order search term is an array

    The products list and wc_order_search() cleaned the search term with wc_clean(), which keeps an array as an array, and passed it on to data store methods that need a string. A URL such as ?s[]=x gets there as an array: the products list failed in stristr(), and with orders stored as posts the order search failed in addcslashes(), both with a TypeError. sanitize_text_field() gives the same result as wc_clean() for a string, since wc_clean() calls it, and turns an array into an empty string. Includes a test for the order search.

    * Fix remaining argument types at data store calls

    The last four errors are about types only; nothing changes at runtime. strtotime() and ceil() return int|false and float where an int is expected, and the casts keep the values they had: get_unpaid_orders() already passed the timestamp through absint(), so false became 0 before too. The unpaid orders line keeps current_time( 'timestamp' ), because get_unpaid_orders() expects a site-local timestamp, and says so to phpcs. The stock stats report called get_data() without its required argument, so __call() passed null, which that store ignores; it now passes an empty array. The deprecated get_matching_variation() passes $this from an abstract parent class, where it is always a WC_Product at runtime, and an instanceof check tells PHPStan so. PHPStan passes again from this commit on.

    * Add changelog entry for data store PHPStan types

    Merchants only see the fixes; the PHPStan changes are internal, so the entry names the fatal errors that no longer happen.

    * Report both return types for truthy non-true webhook pagination

    search_webhooks() paginates on any truthy paginate value, but the conditional
    return type only gave stdClass for literal true, so a call with paginate => 1
    was typed as int[] while it returns an object.

    * Skip stock bookkeeping when the stock owner cannot be loaded

    wc_update_product_stock() returns false when the product that manages a
    variation's stock cannot be loaded. Reducing and restoring order stock only
    checked for WP_Error, so they marked the item as reduced, or cleared that mark,
    although the stock did not change. They now add the existing error note and
    skip the item.

    * Count only processed notifications in stock notification bulk actions

    The bulk actions skip notifications that cannot be loaded, but the notice still
    counted every selected ID, and showed a success notice when nothing changed.

    * Return no matches for a product or order search term with no text

    A term that is empty after sanitizing, such as an array or only a tag, searched
    for an empty string, which matches every product or order. For products, that
    also put every product ID into the list table query.

    * Document that a data store delete() may return a value

    WC_Data_Store::delete() returns what the data store returns, and the order item
    data stores return the number of deleted rows. The interface documented the
    method as void, which PHPStan reports now that it knows the wrapped store
    implements this interface.

    * Remove PHPStan ignores for data store calls guarded by has_callable()

    These ignores were added on trunk after this branch started. PHPStan now checks
    these calls through WC_Data_Store and the has_callable() extension, and reports
    the ignores as unused.

    * Skip refund and line item stock bookkeeping when the stock owner cannot be loaded

    wc_update_product_stock() returns false when the product that manages a
    variation's stock cannot be loaded. Restocking refunded items and adjusting line
    item stock treated that as success, so they changed _reduced_stock and the
    refund restock tally although the stock did not change. Restocking now adds the
    existing error note and skips the item, and the line item adjustment reports no
    change.

    * Restore the PHPStan rule test runner for the has_callable() extension

    #71526 removed StagedWriteRule together with the PHPUnit config, composer script and CI step that ran the PHPStan rule tests. The has_callable() extension test used the same setup, so after that nothing ran it. This brings the setup back, trimmed to the WC_Data_Store stub that the extension test needs.

diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml
index 00fefa100d1..9f2227f4726 100644
--- a/.github/workflows/phpstan.yml
+++ b/.github/workflows/phpstan.yml
@@ -33,6 +33,10 @@ jobs:
               working-directory: plugins/woocommerce
               run: XDEBUG_MODE=off composer install --quiet

+            - name: 'Run PHPStan rule tests'
+              working-directory: plugins/woocommerce
+              run: composer test:phpstan-rules
+
             - name: 'Create tmp directory'
               working-directory: plugins/woocommerce
               run: mkdir -p tmp
diff --git a/plugins/woocommerce/changelog/phpstan-data-store-types b/plugins/woocommerce/changelog/phpstan-data-store-types
new file mode 100644
index 00000000000..84bb4bfde3d
--- /dev/null
+++ b/plugins/woocommerce/changelog/phpstan-data-store-types
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix fatal errors when updating stock, or acting on stock notifications in the admin, for items that can no longer be loaded.
diff --git a/plugins/woocommerce/composer.json b/plugins/woocommerce/composer.json
index b9922990e2f..4a40d1141c3 100644
--- a/plugins/woocommerce/composer.json
+++ b/plugins/woocommerce/composer.json
@@ -117,6 +117,9 @@
 		},
 		"classmap": [
 			"tests/legacy/unit-tests/rest-api/Helpers"
+		],
+		"exclude-from-classmap": [
+			"tests/Tools/phpstan/data/"
 		]
 	},
 	"scripts": {
@@ -165,6 +168,9 @@
 		],
 		"phpstan:baseline": [
 			"vendor/bin/phpstan analyse --configuration=phpstan.neon --memory-limit=4G --generate-baseline=phpstan-baseline.neon"
+		],
+		"test:phpstan-rules": [
+			"phpunit -c tests/Tools/phpstan/phpunit.xml"
 		]
 	},
 	"extra": {
diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php
index 547b00423ba..c6b8cdd6189 100644
--- a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php
+++ b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php
@@ -402,7 +402,6 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
 		$data_store = $this->data_store;

 		if ( $data_store->has_callable( 'delete_items_by_ids' ) ) {
-			// @phpstan-ignore-next-line -- Optional data store method checked above.
 			$data_store->delete_items_by_ids( $this, $item_ids );
 		} else {
 			// Custom data stores may not support bulk deletion by IDs, so delete the snapshotted items individually
@@ -480,7 +479,6 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
 		$data_store = $this->data_store;

 		if ( $data_store->has_callable( 'get_item_ids' ) ) {
-			// @phpstan-ignore-next-line -- Optional data store method checked above.
 			$item_ids = $data_store->get_item_ids( $this, $type );

 			return array_values(
@@ -1659,7 +1657,6 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
 					$coupon_data_store = $coupon->get_data_store();
 					$coupon_aliases    = $user_ids_and_emails;
 					if ( $coupon_data_store instanceof WC_Data_Store && $coupon_data_store->has_callable( 'add_recorded_user_ids_to_aliases' ) ) {
-						// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the coupon data store instance.)
 						$coupon_aliases = $coupon_data_store->add_recorded_user_ids_to_aliases( $coupon, $user_ids_and_emails );
 					}
 					$held_key_for_user = $this->hold_coupon_for_users( $coupon, $coupon_aliases, $user_alias );
@@ -1836,7 +1833,6 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
 		 */
 		$order_data_store = $this->get_data_store();
 		// Read before the save: when the save itself records the usage, the status hook has already counted this coupon.
-		// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the underlying order data store instance).
 		$recorded_before_save = $order_data_store->has_callable( 'get_recorded_coupon_usage_counts' ) && $order_data_store->get_recorded_coupon_usage_counts( $this );

 		$this->save();
@@ -1851,7 +1847,6 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
 			$used_by = $this->get_billing_email();
 		}

-		// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the underlying order data store instance.)
 		if ( $recorded_before_save && $order_data_store->has_callable( 'get_recorded_coupon_usage_counts' ) && $order_data_store->get_recorded_coupon_usage_counts( $this ) ) {
 			$coupon->increase_usage_count( $used_by, $this instanceof WC_Order ? $this : null );
 			if ( $coupon->get_id() ) {
@@ -1989,8 +1984,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
 		 * @var WC_Data_Store $order_data_store
 		 */
 		$order_data_store = $this->get_data_store();
-		// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the underlying order data store instance.)
-		$has_recorded = $order_data_store->has_callable( 'get_recorded_coupon_usage_counts' ) && $order_data_store->get_recorded_coupon_usage_counts( $this );
+		$has_recorded     = $order_data_store->has_callable( 'get_recorded_coupon_usage_counts' ) && $order_data_store->get_recorded_coupon_usage_counts( $this );

 		$used_by = $this->get_user_id();
 		if ( ! $used_by && is_callable( array( $this, 'get_billing_email' ) ) ) {
@@ -2098,7 +2092,6 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
 			return true;
 		}

-		// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the underlying order data store instance.)
 		return $order_data_store->get_stored_recorded_coupon_usage_counts( $this );
 	}

diff --git a/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-products.php b/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-products.php
index e769532edc6..ae0170f41cb 100644
--- a/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-products.php
+++ b/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-products.php
@@ -773,9 +773,9 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {

 		// Search using CRUD.
 		if ( ! empty( $query_vars['s'] ) ) {
-			$search_term                  = wc_clean( wp_unslash( $query_vars['s'] ) );
+			$search_term                  = sanitize_text_field( wp_unslash( $query_vars['s'] ) );
 			$data_store                   = WC_Data_Store::load( 'product' );
-			$ids                          = $data_store->search_products( $search_term, '', true, true );
+			$ids                          = '' === $search_term ? array() : $data_store->search_products( $search_term, '', true, true );
 			$query_vars['post__in']       = array_merge( $ids, array( 0 ) );
 			$query_vars['product_search'] = true;
 			$default_search_order         = $this->get_default_search_order( $query_vars );
diff --git a/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php b/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
index 6ff8d3b82f7..80f5fa818b5 100644
--- a/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
+++ b/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
@@ -488,7 +488,6 @@ class WC_Meta_Box_Product_Data {
 		 */
 		$data_store = $product->get_data_store();
 		if ( $data_store->has_callable( 'refresh_product_lookup_table' ) ) {
-			// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the underlying product data store instance.)
 			$data_store->refresh_product_lookup_table( $product->get_id() );
 		}
 	}
diff --git a/plugins/woocommerce/includes/admin/wc-admin-functions.php b/plugins/woocommerce/includes/admin/wc-admin-functions.php
index d81f9e9f5fa..204a5a62539 100644
--- a/plugins/woocommerce/includes/admin/wc-admin-functions.php
+++ b/plugins/woocommerce/includes/admin/wc-admin-functions.php
@@ -298,7 +298,7 @@ function wc_maybe_adjust_line_item_product_stock( $item, $item_quantity = -1 ) {
 		return false;
 	}

-	if ( is_wp_error( $new_stock ) ) {
+	if ( is_wp_error( $new_stock ) || false === $new_stock ) {
 		return $new_stock;
 	}

diff --git a/plugins/woocommerce/includes/class-wc-cart.php b/plugins/woocommerce/includes/class-wc-cart.php
index 75be1fd58ac..ff41e49e506 100644
--- a/plugins/woocommerce/includes/class-wc-cart.php
+++ b/plugins/woocommerce/includes/class-wc-cart.php
@@ -2076,7 +2076,6 @@ class WC_Cart extends WC_Legacy_Cart {
 					}
 					// The larger count keeps a custom store's get_usage_by_email() override in effect.
 					if ( $uses_alias ) {
-						// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the coupon data store instance.)
 						$usage_count = max( $usage_count, (int) $coupon_data_store->get_usage_by_aliases( $coupon, $aliases ) );
 					}
 					if ( $coupon_data_store && $usage_count >= $coupon_usage_limit ) {
diff --git a/plugins/woocommerce/includes/class-wc-data-store.php b/plugins/woocommerce/includes/class-wc-data-store.php
index 13f96ac3b08..6cca87228f3 100644
--- a/plugins/woocommerce/includes/class-wc-data-store.php
+++ b/plugins/woocommerce/includes/class-wc-data-store.php
@@ -11,13 +11,63 @@ defined( 'ABSPATH' ) || exit;

 /**
  * Data store class.
+ *
+ * Methods not defined here are forwarded to the wrapped store by __call(). The @mixin tag lets static analysis
+ * see them. DataStoreMap lists the default store for each object type, which load() uses to pick T; filters can
+ * replace a store at runtime, so T describes the default.
+ *
+ * @template-covariant T of object = object
+ * @mixin T
+ *
+ * @phpstan-type DataStoreMap array{
+ *     coupon: WC_Coupon_Data_Store_CPT,
+ *     customer: WC_Customer_Data_Store,
+ *     'customer-download': WC_Customer_Download_Data_Store,
+ *     'customer-download-log': WC_Customer_Download_Log_Data_Store,
+ *     'customer-session': WC_Customer_Data_Store_Session,
+ *     order: WC_Order_Data_Store_CPT,
+ *     'order-refund': WC_Order_Refund_Data_Store_CPT,
+ *     'order-item': WC_Order_Item_Data_Store,
+ *     'order-item-coupon': WC_Order_Item_Coupon_Data_Store,
+ *     'order-item-fee': WC_Order_Item_Fee_Data_Store,
+ *     'order-item-product': WC_Order_Item_Product_Data_Store,
+ *     'order-item-shipping': WC_Order_Item_Shipping_Data_Store,
+ *     'order-item-tax': WC_Order_Item_Tax_Data_Store,
+ *     'payment-token': WC_Payment_Token_Data_Store,
+ *     product: WC_Product_Data_Store_CPT,
+ *     'product-grouped': WC_Product_Grouped_Data_Store_CPT,
+ *     'product-variable': WC_Product_Variable_Data_Store_CPT,
+ *     'product-variation': WC_Product_Variation_Data_Store_CPT,
+ *     'shipping-zone': WC_Shipping_Zone_Data_Store,
+ *     webhook: WC_Webhook_Data_Store,
+ *     'admin-note': \Automattic\WooCommerce\Admin\Notes\DataStore,
+ *     'order-fulfillment': \Automattic\WooCommerce\Admin\Features\Fulfillments\DataStore\FulfillmentsDataStore,
+ *     stock_notification: \Automattic\WooCommerce\Internal\DataStores\StockNotifications\StockNotificationsDataStore,
+ *     'report-revenue-stats': \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore,
+ *     'report-orders': \Automattic\WooCommerce\Admin\API\Reports\Orders\DataStore,
+ *     'report-orders-stats': \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore,
+ *     'report-products': \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore,
+ *     'report-variations': \Automattic\WooCommerce\Admin\API\Reports\Variations\DataStore,
+ *     'report-products-stats': \Automattic\WooCommerce\Admin\API\Reports\Products\Stats\DataStore,
+ *     'report-variations-stats': \Automattic\WooCommerce\Admin\API\Reports\Variations\Stats\DataStore,
+ *     'report-categories': \Automattic\WooCommerce\Admin\API\Reports\Categories\DataStore,
+ *     'report-taxes': \Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore,
+ *     'report-taxes-stats': \Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats\DataStore,
+ *     'report-coupons': \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore,
+ *     'report-coupons-stats': \Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats\DataStore,
+ *     'report-downloads': \Automattic\WooCommerce\Admin\API\Reports\Downloads\DataStore,
+ *     'report-downloads-stats': \Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats\DataStore,
+ *     'report-customers': \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore,
+ *     'report-customers-stats': \Automattic\WooCommerce\Admin\API\Reports\Customers\Stats\DataStore,
+ *     'report-stock-stats': \Automattic\WooCommerce\Admin\API\Reports\Stock\Stats\DataStore,
+ * }
  */
 class WC_Data_Store {

 	/**
 	 * Contains an instance of the data store class that we are working with.
 	 *
-	 * @var WC_Data_Store
+	 * @var WC_Object_Data_Store_Interface
 	 */
 	private $instance = null;

@@ -134,6 +184,10 @@ class WC_Data_Store {
 	 * @since 3.0.0
 	 * @throws Exception When validation fails.
 	 * @return WC_Data_Store
+	 *
+	 * @phpstan-template K of string
+	 * @phpstan-param K $object_type
+	 * @phpstan-return (K is key-of<DataStoreMap> ? WC_Data_Store<DataStoreMap[K]> : WC_Data_Store)
 	 */
 	public static function load( $object_type ) {
 		return new WC_Data_Store( $object_type );
diff --git a/plugins/woocommerce/includes/class-wc-payment-tokens.php b/plugins/woocommerce/includes/class-wc-payment-tokens.php
index 618b5dd7cc9..ed23e99b8ff 100644
--- a/plugins/woocommerce/includes/class-wc-payment-tokens.php
+++ b/plugins/woocommerce/includes/class-wc-payment-tokens.php
@@ -144,8 +144,8 @@ class WC_Payment_Tokens {
 	 *
 	 * @since 2.6.0
 	 *
-	 * @param int    $token_id Token ID.
-	 * @param object $token_result Token result.
+	 * @param int           $token_id     Token ID.
+	 * @param stdClass|null $token_result Token result.
 	 * @return null|WC_Payment_Token Returns a valid payment token or null if no token can be found.
 	 */
 	public static function get( $token_id, $token_result = null ) {
diff --git a/plugins/woocommerce/includes/class-wc-privacy-erasers.php b/plugins/woocommerce/includes/class-wc-privacy-erasers.php
index 5ec3668ad7f..1f5a613137e 100644
--- a/plugins/woocommerce/includes/class-wc-privacy-erasers.php
+++ b/plugins/woocommerce/includes/class-wc-privacy-erasers.php
@@ -32,7 +32,6 @@ class WC_Privacy_Erasers {

 		$coupon_data_store = WC_Data_Store::load( 'coupon' );
 		if ( $coupon_data_store->has_callable( 'remove_used_by_email_records' ) ) {
-			// @phpstan-ignore-next-line method.notFound (WC_Data_Store forwards the call to the coupon data store.)
 			$removed = $coupon_data_store->remove_used_by_email_records( (string) $email_address, $user instanceof WP_User ? $user->ID : 0 );
 			if ( $removed ) {
 				$response['messages'][]    = __( 'Removed customer email from coupon usage records', 'woocommerce' );
diff --git a/plugins/woocommerce/includes/class-wc-structured-data.php b/plugins/woocommerce/includes/class-wc-structured-data.php
index 7b3c93d1f04..089a73bef30 100644
--- a/plugins/woocommerce/includes/class-wc-structured-data.php
+++ b/plugins/woocommerce/includes/class-wc-structured-data.php
@@ -1099,8 +1099,7 @@ class WC_Structured_Data {
 			$match_attributes[ $key ] = wc_clean( wp_unslash( $_GET[ $key ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
 		}

-		$data_store = WC_Data_Store::load( 'product' );
-		// @phpstan-ignore-next-line method.notFound (Called via __call() on the underlying product data store instance.)
+		$data_store   = WC_Data_Store::load( 'product' );
 		$variation_id = $data_store->find_matching_product_variation( $product, $match_attributes );

 		if ( ! $variation_id ) {
diff --git a/plugins/woocommerce/includes/data-stores/class-wc-customer-data-store.php b/plugins/woocommerce/includes/data-stores/class-wc-customer-data-store.php
index 839ecfc7dca..f6c68619fbe 100644
--- a/plugins/woocommerce/includes/data-stores/class-wc-customer-data-store.php
+++ b/plugins/woocommerce/includes/data-stores/class-wc-customer-data-store.php
@@ -670,7 +670,7 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
 	 * Query customers ordered by allowed fields.
 	 *
 	 * @param array $args Query arguments.
-	 * @return object Object containing customers in the requested order, total, and max_num_pages.
+	 * @return stdClass Object containing customers in the requested order, total, and max_num_pages.
 	 */
 	public function query_customers( array $args = array() ) {
 		global $wpdb;
diff --git a/plugins/woocommerce/includes/data-stores/class-wc-order-item-data-store.php b/plugins/woocommerce/includes/data-stores/class-wc-order-item-data-store.php
index b80c77501e8..d09b8a0bbca 100644
--- a/plugins/woocommerce/includes/data-stores/class-wc-order-item-data-store.php
+++ b/plugins/woocommerce/includes/data-stores/class-wc-order-item-data-store.php
@@ -155,7 +155,7 @@ class WC_Order_Item_Data_Store implements WC_Order_Item_Data_Store_Interface {
 	 * Get the order item type based on Item ID.
 	 *
 	 * @since 3.0.0
-	 * @param int $item_id Item ID.
+	 * @param int|string $item_id Item ID, as an integer or a numeric string.
 	 * @return string|null Order item type or null if no order item entry found.
 	 */
 	public function get_order_item_type( $item_id ) {
diff --git a/plugins/woocommerce/includes/data-stores/class-wc-payment-token-data-store.php b/plugins/woocommerce/includes/data-stores/class-wc-payment-token-data-store.php
index ad0392a1bbe..714c2d44c59 100644
--- a/plugins/woocommerce/includes/data-stores/class-wc-payment-token-data-store.php
+++ b/plugins/woocommerce/includes/data-stores/class-wc-payment-token-data-store.php
@@ -313,7 +313,7 @@ class WC_Payment_Token_Data_Store extends WC_Data_Store_WP implements WC_Object_
 	 *
 	 * @since 3.0.0
 	 * @param int $user_id User ID.
-	 * @return object
+	 * @return stdClass|null
 	 */
 	public function get_users_default_token( $user_id ) {
 		global $wpdb;
@@ -331,7 +331,7 @@ class WC_Payment_Token_Data_Store extends WC_Data_Store_WP implements WC_Object_
 	 *
 	 * @since 3.0.0
 	 * @param int $token_id Token ID.
-	 * @return object
+	 * @return stdClass|null
 	 */
 	public function get_token_by_id( $token_id ) {
 		global $wpdb;
diff --git a/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php b/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php
index 61f9138fd85..dc495eca562 100644
--- a/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php
+++ b/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php
@@ -1798,11 +1798,11 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
 	 * Return a list of related products (using data like categories and IDs).
 	 *
 	 * @since 3.0.0
-	 * @param array $cats_array  List of categories IDs.
-	 * @param array $tags_array  List of tags IDs.
-	 * @param array $exclude_ids Excluded IDs.
-	 * @param int   $limit       Limit of results.
-	 * @param int   $product_id  Product ID.
+	 * @param array    $cats_array  List of categories IDs.
+	 * @param array    $tags_array  List of tags IDs.
+	 * @param array    $exclude_ids Excluded IDs.
+	 * @param int      $limit       Limit of results.
+	 * @param int|null $product_id  Product ID. Only passed to the woocommerce_product_related_posts_query filter.
 	 * @return array
 	 */
 	public function get_related_products( $cats_array, $tags_array, $exclude_ids, $limit, $product_id ) {
@@ -2344,7 +2344,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
 	 *
 	 * @since 3.0.0
 	 * @param int $product_id Product ID.
-	 * @return bool|string
+	 * @return string|false
 	 */
 	public function get_product_type( $product_id ) {
 		$cache_key    = WC_Cache_Helper::get_cache_prefix( 'product_' . $product_id ) . '_type_' . $product_id;
diff --git a/plugins/woocommerce/includes/data-stores/class-wc-shipping-zone-data-store.php b/plugins/woocommerce/includes/data-stores/class-wc-shipping-zone-data-store.php
index 78803fc3701..8c9ce0858c4 100644
--- a/plugins/woocommerce/includes/data-stores/class-wc-shipping-zone-data-store.php
+++ b/plugins/woocommerce/includes/data-stores/class-wc-shipping-zone-data-store.php
@@ -288,7 +288,7 @@ class WC_Shipping_Zone_Data_Store extends WC_Data_Store_WP implements WC_Object_
 	 *
 	 * @since  3.0.0
 	 * @param  int $instance_id Instance ID.
-	 * @return object
+	 * @return stdClass|null
 	 */
 	public function get_method( $instance_id ) {
 		global $wpdb;
@@ -299,7 +299,7 @@ class WC_Shipping_Zone_Data_Store extends WC_Data_Store_WP implements WC_Object_
 	 * Find a matching zone ID for a given package.
 	 *
 	 * @since  3.0.0
-	 * @param  object $package Package information.
+	 * @param  array $package Package information.
 	 * @return int
 	 */
 	public function get_zone_id_from_package( $package ) {
diff --git a/plugins/woocommerce/includes/data-stores/class-wc-webhook-data-store.php b/plugins/woocommerce/includes/data-stores/class-wc-webhook-data-store.php
index 7fdc33b5d37..adcfb8917c5 100644
--- a/plugins/woocommerce/includes/data-stores/class-wc-webhook-data-store.php
+++ b/plugins/woocommerce/includes/data-stores/class-wc-webhook-data-store.php
@@ -243,7 +243,9 @@ class WC_Webhook_Data_Store implements WC_Webhook_Data_Store_Interface {
 	 * Search webhooks.
 	 *
 	 * @param  array $args Search arguments.
-	 * @return array|object
+	 * @return int[]|stdClass Webhook IDs, or an object with webhooks, total and max_num_pages when paginate is enabled.
+	 *
+	 * @phpstan-return ($args is array{paginate: true} ? stdClass : ($args is array{paginate: false|0|''|'0'|null} ? int[] : ($args is array{paginate: mixed} ? int[]|stdClass : int[])))
 	 */
 	public function search_webhooks( $args ) {
 		global $wpdb;
diff --git a/plugins/woocommerce/includes/interfaces/class-wc-object-data-store-interface.php b/plugins/woocommerce/includes/interfaces/class-wc-object-data-store-interface.php
index 1affd4ebf80..bbdf3ba94f7 100644
--- a/plugins/woocommerce/includes/interfaces/class-wc-object-data-store-interface.php
+++ b/plugins/woocommerce/includes/interfaces/class-wc-object-data-store-interface.php
@@ -36,9 +36,11 @@ interface WC_Object_Data_Store_Interface {
 	/**
 	 * Deletes a record from the database.
 	 *
+	 * Implementations might return a value, e.g. order item data stores return the number of deleted rows.
+	 *
 	 * @param  WC_Data $data Data object.
 	 * @param  array   $args Array of args to pass to the delete method.
-	 * @return void
+	 * @return mixed What the implementation returns, if anything.
 	 */
 	public function delete( &$data, $args = array() );

diff --git a/plugins/woocommerce/includes/interfaces/class-wc-shipping-zone-data-store-interface.php b/plugins/woocommerce/includes/interfaces/class-wc-shipping-zone-data-store-interface.php
index 65d7243e2c7..dadce158cde 100644
--- a/plugins/woocommerce/includes/interfaces/class-wc-shipping-zone-data-store-interface.php
+++ b/plugins/woocommerce/includes/interfaces/class-wc-shipping-zone-data-store-interface.php
@@ -59,7 +59,7 @@ interface WC_Shipping_Zone_Data_Store_Interface {
 	/**
 	 * Find a matching zone ID for a given package.
 	 *
-	 * @param object $package Zone package object.
+	 * @param array $package Zone package.
 	 * @return int
 	 */
 	public function get_zone_id_from_package( $package );
diff --git a/plugins/woocommerce/includes/legacy/abstract-wc-legacy-product.php b/plugins/woocommerce/includes/legacy/abstract-wc-legacy-product.php
index 4783b3d5698..cba5e9674de 100644
--- a/plugins/woocommerce/includes/legacy/abstract-wc-legacy-product.php
+++ b/plugins/woocommerce/includes/legacy/abstract-wc-legacy-product.php
@@ -627,6 +627,9 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
 	 */
 	public function get_matching_variation( $match_attributes = array() ) {
 		wc_deprecated_function( 'WC_Product::get_matching_variation', '3.0', 'Product data store find_matching_product_variation' );
+		if ( ! $this instanceof WC_Product ) {
+			return 0;
+		}
 		$data_store = WC_Data_Store::load( 'product' );
 		return $data_store->find_matching_product_variation( $this, $match_attributes );
 	}
diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version1/class-wc-rest-webhooks-v1-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version1/class-wc-rest-webhooks-v1-controller.php
index b5b9c691a7d..bf9678d4453 100644
--- a/plugins/woocommerce/includes/rest-api/Controllers/Version1/class-wc-rest-webhooks-v1-controller.php
+++ b/plugins/woocommerce/includes/rest-api/Controllers/Version1/class-wc-rest-webhooks-v1-controller.php
@@ -267,8 +267,13 @@ class WC_REST_Webhooks_V1_Controller extends WC_REST_Controller {
 		$prepared_args['paginate'] = true;

 		// Get the webhooks.
-		$webhooks    = array();
-		$data_store  = WC_Data_Store::load( 'webhook' );
+		$webhooks   = array();
+		$data_store = WC_Data_Store::load( 'webhook' );
+		/**
+		 * Paginated results, as paginate is set to true above.
+		 *
+		 * @var stdClass $results
+		 */
 		$results     = $data_store->search_webhooks( $prepared_args );
 		$webhook_ids = $results->webhooks;

diff --git a/plugins/woocommerce/includes/wc-order-functions.php b/plugins/woocommerce/includes/wc-order-functions.php
index 70c77aaad91..0b47b0e0962 100644
--- a/plugins/woocommerce/includes/wc-order-functions.php
+++ b/plugins/woocommerce/includes/wc-order-functions.php
@@ -862,6 +862,12 @@ function wc_restock_refunded_items( $order, $refunded_line_items ) {
 		$old_stock = $product->get_stock_quantity();
 		$new_stock = wc_update_product_stock( $product, $qty_to_refund, 'increase' );

+		if ( is_wp_error( $new_stock ) || false === $new_stock ) {
+			/* translators: %s item name. */
+			$order->add_order_note( sprintf( __( 'Unable to restore stock for item %s.', 'woocommerce' ), $item->get_name() ), 0, false, array( 'note_group' => OrderNoteGroup::ERROR ) );
+			continue;
+		}
+
 		// Update _reduced_stock meta to track changes.
 		$item_stock_reduced = $item_stock_reduced - $qty_to_refund;

@@ -969,11 +975,17 @@ add_action( 'woocommerce_order_status_refunded', 'wc_order_fully_refunded' );
  *
  * @since  2.6.0
  * @param  string $term Term to search.
- * @return array List of orders ID.
+ * @return array List of orders ID, empty when the term has no text left after sanitizing.
  */
 function wc_order_search( $term ) {
+	$term = str_replace( 'Order #', '', sanitize_text_field( $term ) );
+
+	if ( '' === $term ) {
+		return array();
+	}
+
 	$data_store = WC_Data_Store::load( 'order' );
-	return $data_store->search_orders( str_replace( 'Order #', '', wc_clean( $term ) ) );
+	return $data_store->search_orders( $term );
 }

 /**
@@ -1085,7 +1097,6 @@ function wc_update_coupon_usage_counts( $order_id ) {
 	if ( $is_invalid && $has_recorded ) {
 		$action = 'reduce';
 		if ( $data_store->has_callable( 'clear_recorded_coupon_usage_counts' ) ) {
-			// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the underlying order data store instance.)
 			if ( ! $data_store->clear_recorded_coupon_usage_counts( $order ) ) {
 				// Another request already gave the uses back, or changed the order status since this order was loaded.
 				wc_release_coupons_for_order( $order );
@@ -1097,7 +1108,6 @@ function wc_update_coupon_usage_counts( $order_id ) {

 		if ( $data_store->has_callable( 'get_item_ids' ) ) {
 			try {
-				// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the underlying order data store instance.)
 				$stored_item_ids = $data_store->get_item_ids( $order, 'coupon' );
 			} catch ( Exception $e ) {
 				// Give nothing back rather than risk giving a use back twice.
@@ -1207,7 +1217,7 @@ function wc_cancel_unpaid_orders() {
 	}

 	$data_store    = WC_Data_Store::load( 'order' );
-	$unpaid_orders = $data_store->get_unpaid_orders( strtotime( '-' . absint( $held_duration ) . ' MINUTES', current_time( 'timestamp' ) ) );
+	$unpaid_orders = $data_store->get_unpaid_orders( (int) strtotime( '-' . absint( $held_duration ) . ' MINUTES', current_time( 'timestamp' ) ) ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested -- get_unpaid_orders() expects a site-local timestamp.

 	if ( $unpaid_orders ) {
 		foreach ( $unpaid_orders as $unpaid_order ) {
diff --git a/plugins/woocommerce/includes/wc-product-functions.php b/plugins/woocommerce/includes/wc-product-functions.php
index 7cfbda8c3c5..19411bbd1ea 100644
--- a/plugins/woocommerce/includes/wc-product-functions.php
+++ b/plugins/woocommerce/includes/wc-product-functions.php
@@ -689,7 +689,7 @@ function wc_apply_sale_state_for_product( WC_Product $product, string $mode ): v
 	// not in the tracked props list in handle_updated_props().
 	$data_store = WC_Data_Store::load( 'product' );
 	if ( $data_store->has_callable( 'refresh_product_lookup_table' ) ) {
-		$data_store->refresh_product_lookup_table( $product_id ); // @phpstan-ignore method.notFound (Guarded by has_callable() and called via __call() on the underlying product data store instance.)
+		$data_store->refresh_product_lookup_table( $product_id );
 	}

 	wc_delete_product_transients( $product_id );
diff --git a/plugins/woocommerce/includes/wc-stock-functions.php b/plugins/woocommerce/includes/wc-stock-functions.php
index a87fc7ae70d..3551a68bd8c 100644
--- a/plugins/woocommerce/includes/wc-stock-functions.php
+++ b/plugins/woocommerce/includes/wc-stock-functions.php
@@ -40,7 +40,12 @@ function wc_update_product_stock( $product, $stock_quantity = null, $operation =
 		// Some products (variations) can have their stock managed by their parent. Get the correct object to be updated here.
 		$product_id_with_stock = $product->get_stock_managed_by_id();
 		$product_with_stock    = $product_id_with_stock !== $product->get_id() ? wc_get_product( $product_id_with_stock ) : $product;
-		$data_store            = WC_Data_Store::load( 'product' );
+
+		if ( ! $product_with_stock ) {
+			return false;
+		}
+
+		$data_store = WC_Data_Store::load( 'product' );

 		// Fire actions to let 3rd parties know the stock is about to be changed.
 		if ( $product_with_stock->is_type( ProductType::VARIATION ) ) {
@@ -207,7 +212,7 @@ function wc_reduce_stock_levels( $order_id ) {
 		$item_name = $product->get_name();
 		$new_stock = wc_update_product_stock( $product, $qty, 'decrease' );

-		if ( is_wp_error( $new_stock ) ) {
+		if ( is_wp_error( $new_stock ) || false === $new_stock ) {
 			/* translators: %s item name. */
 			$order->add_order_note( sprintf( __( 'Unable to reduce stock for item %s.', 'woocommerce' ), $item_name ), false, false, array( 'note_group' => OrderNoteGroup::ERROR ) );
 			continue;
@@ -390,7 +395,7 @@ function wc_increase_stock_levels( $order_id ) {
 		$new_stock = wc_update_product_stock( $product, $item_stock_reduced, 'increase' );
 		$old_stock = $new_stock - $item_stock_reduced;

-		if ( is_wp_error( $new_stock ) ) {
+		if ( is_wp_error( $new_stock ) || false === $new_stock ) {
 			/* translators: %s item name. */
 			$order->add_order_note( sprintf( __( 'Unable to restore stock for item %s.', 'woocommerce' ), $item_name ), false, false, array( 'note_group' => OrderNoteGroup::ERROR ) );
 			continue;
diff --git a/plugins/woocommerce/phpcs.xml b/plugins/woocommerce/phpcs.xml
index 6398838d27e..96f8e9a6940 100644
--- a/plugins/woocommerce/phpcs.xml
+++ b/plugins/woocommerce/phpcs.xml
@@ -26,6 +26,8 @@
 	<exclude-pattern>tests/e2e/bin/</exclude-pattern>
 	<!-- Custom PHPCS sniffs and their fixtures follow PHPCS naming/structure, not the WooCommerce ruleset. -->
 	<exclude-pattern>tests/Tools/phpcs/</exclude-pattern>
+	<!-- Fixtures that the PHPStan extension tests analyse. -->
+	<exclude-pattern>tests/Tools/phpstan/data/</exclude-pattern>

 	<!-- Only check PHP files. -->
 	<arg name="extensions" value="php" />
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index ba4458197a8..949ff9ba529 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -3078,18 +3078,6 @@ parameters:
 			count: 1
 			path: includes/admin/class-wc-admin-upload-downloadable-product.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_count_webhooks_by_status\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/admin/class-wc-admin-webhooks-table-list.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:search_webhooks\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/admin/class-wc-admin-webhooks-table-list.php
-
 		-
 			message: '#^Method WC_Admin_Webhooks_Table_List\:\:display_tablenav\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -3126,12 +3114,6 @@ parameters:
 			count: 1
 			path: includes/admin/class-wc-admin-webhooks-table-list.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_count_webhooks_by_status\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/admin/class-wc-admin-webhooks.php
-
 		-
 			message: '#^Default value of the parameter \#1 \$webhook \(string\) of method WC_Admin_Webhooks\:\:logs_output\(\) is incompatible with type WC_Webhook\.$#'
 			identifier: parameter.defaultValue
@@ -3708,12 +3690,6 @@ parameters:
 			count: 1
 			path: includes/admin/helper/class-wc-helper.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_notes_with_name\(\)\.$#'
-			identifier: method.notFound
-			count: 2
-			path: includes/admin/helper/class-wc-helper.php
-
 		-
 			message: '#^Cannot access offset ''_filename'' on array\|bool\.$#'
 			identifier: offsetAccess.nonOffsetAccessible
@@ -4614,12 +4590,6 @@ parameters:
 			count: 2
 			path: includes/admin/list-tables/class-wc-admin-list-table-products.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:search_products\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/admin/list-tables/class-wc-admin-list-table-products.php
-
 		-
 			message: '#^Call to an undefined method object\:\:get_id\(\)\.$#'
 			identifier: method.notFound
@@ -5082,12 +5052,6 @@ parameters:
 			count: 1
 			path: includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_by_order_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/admin/meta-boxes/class-wc-meta-box-order-actions.php
-
 		-
 			message: '#^Call to an undefined method WC_Email\:\:trigger\(\)\.$#'
 			identifier: method.notFound
@@ -5286,12 +5250,6 @@ parameters:
 			count: 1
 			path: includes/admin/meta-boxes/class-wc-meta-box-order-data.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_downloads\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/admin/meta-boxes/class-wc-meta-box-order-downloads.php
-
 		-
 			message: '#^Method WC_Meta_Box_Order_Downloads\:\:output\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -6162,12 +6120,6 @@ parameters:
 			count: 1
 			path: includes/admin/notes/class-wc-notes-refund-returns.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_notes_with_name\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/admin/notes/class-wc-notes-refund-returns.php
-
 		-
 			message: '#^Call to an undefined method object\:\:get_action\(\)\.$#'
 			identifier: method.notFound
@@ -6216,12 +6168,6 @@ parameters:
 			count: 1
 			path: includes/admin/notes/class-wc-notes-refund-returns.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_notes_with_name\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/admin/notes/class-wc-notes-run-db-update.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Admin\\Notes\\Note\:\:add_action\(\) invoked with 7 parameters, 2\-6 required\.$#'
 			identifier: arguments.count
@@ -7980,18 +7926,6 @@ parameters:
 			count: 5
 			path: includes/admin/views/html-report-by-date.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_stock_reduced\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/admin/wc-admin-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:set_stock_reduced\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/admin/wc-admin-functions.php
-
 		-
 			message: '#^Call to an undefined method WC_Order_Item\:\:get_product\(\)\.$#'
 			identifier: method.notFound
@@ -8208,30 +8142,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-ajax.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_by_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-ajax.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:find_matching_product_variation\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-ajax.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:search_customers\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-ajax.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:search_products\(\)\.$#'
-			identifier: method.notFound
-			count: 2
-			path: includes/class-wc-ajax.php
-
 		-
 			message: '#^Call to an undefined method WC_Order_Item\:\:get_product\(\)\.$#'
 			identifier: method.notFound
@@ -10014,12 +9924,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-cart.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:find_matching_product_variation\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-cart.php
-
 		-
 			message: '#^Call to an undefined method WC_Product\:\:get_variation_attributes\(\)\.$#'
 			identifier: method.notFound
@@ -10614,12 +10518,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-customer-download-log.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_download_logs_count_for_permission\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-customer-download.php
-
 		-
 			message: '#^Call to an undefined method object\:\:read\(\)\.$#'
 			identifier: method.notFound
@@ -10771,13 +10669,7 @@ parameters:
 			path: includes/class-wc-data-store.php

 		-
-			message: '#^Property WC_Data_Store\:\:\$instance \(WC_Data_Store\) does not accept WC_Object_Data_Store_Interface\.$#'
-			identifier: assign.propertyType
-			count: 1
-			path: includes/class-wc-data-store.php
-
-		-
-			message: '#^Property WC_Data_Store\:\:\$instance \(WC_Data_Store\) does not accept object\.$#'
+			message: '#^Property WC_Data_Store\<T of object \= object\>\:\:\$instance \(WC_Object_Data_Store_Interface\) does not accept object\.$#'
 			identifier: assign.propertyType
 			count: 1
 			path: includes/class-wc-data-store.php
@@ -11058,12 +10950,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-download-handler.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_downloads\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-download-handler.php
-
 		-
 			message: '#^Call to an undefined method WC_Order\|WC_Order_Refund\:\:is_download_permitted\(\)\.$#'
 			identifier: method.notFound
@@ -11886,24 +11772,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-meta-data.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_order_item_type\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-order-factory.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_order_type\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-order-factory.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_orders_type\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-order-factory.php
-
 		-
 			message: '#^Call to an undefined method object\:\:get_data_store\(\)\.$#'
 			identifier: method.notFound
@@ -12102,12 +11970,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-order-item-meta.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_downloads\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-order-item-product.php
-
 		-
 			message: '#^Cannot call method backorders_require_notification\(\) on WC_Product\|true\.$#'
 			identifier: method.nonObject
@@ -12450,12 +12312,6 @@ parameters:
 			count: 3
 			path: includes/class-wc-order-item.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:query\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-order-query.php
-
 		-
 			message: '#^Method WC_Order_Refund\:\:get_post_title\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -12757,42 +12613,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-payment-gateways.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_metadata\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-payment-tokens.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_token_by_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-payment-tokens.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_token_type_by_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-payment-tokens.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_tokens\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-payment-tokens.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_users_default_token\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-payment-tokens.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:set_default_status\(\)\.$#'
-			identifier: method.notFound
-			count: 2
-			path: includes/class-wc-payment-tokens.php
-
 		-
 			message: '#^Call to an undefined method object\:\:delete\(\)\.$#'
 			identifier: method.notFound
@@ -12823,36 +12643,6 @@ parameters:
 			count: 3
 			path: includes/class-wc-post-data.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_by_order_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-post-data.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_from_lookup_table\(\)\.$#'
-			identifier: method.notFound
-			count: 2
-			path: includes/class-wc-post-data.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_variations\(\)\.$#'
-			identifier: method.notFound
-			count: 3
-			path: includes/class-wc-post-data.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_attribute_summary\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-post-data.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:untrash_variations\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-post-data.php
-
 		-
 			message: '#^Cannot access property \$slug on WP_Term\|false\.$#'
 			identifier: property.nonObject
@@ -12979,18 +12769,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-privacy-background-process.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_by_user_email\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-privacy-erasers.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_by_user_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-privacy-erasers.php
-
 		-
 			message: '#^Method WC_Privacy_Erasers\:\:remove_order_personal_data\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -13015,18 +12793,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-privacy-exporters.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_download_logs_for_permission\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-privacy-exporters.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_downloads\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-privacy-exporters.php
-
 		-
 			message: '#^Call to an undefined method WC_Order\:\:get_access_expires\(\)\.$#'
 			identifier: method.notFound
@@ -13267,12 +13033,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-product-factory.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_product_type\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-product-factory.php
-
 		-
 			message: '#^Method WC_Product_Factory\:\:get_product\(\) should return bool\|WC_Product but returns object\.$#'
 			identifier: return.type
@@ -13339,12 +13099,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-product-grouped.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:query\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-product-query.php
-
 		-
 			message: '#^@param tag must not be named \$this\. Choose a descriptive alias, for example \$instance\.$#'
 			identifier: phpDoc.parseError
@@ -14497,30 +14251,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-shipping-zones.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_method\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-shipping-zones.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_zone_id_by_instance_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-shipping-zones.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_zone_id_from_package\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-shipping-zones.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_zones\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/class-wc-shipping-zones.php
-
 		-
 			message: '#^Method WC_Shipping_Zones\:\:delete_zone\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -16747,12 +16477,6 @@ parameters:
 			count: 1
 			path: includes/data-stores/class-wc-order-data-store-cpt.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:update_user_by_order_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/data-stores/class-wc-order-data-store-cpt.php
-
 		-
 			message: '#^Cannot access offset string on array\|bool\.$#'
 			identifier: offsetAccess.nonOffsetAccessible
@@ -17461,24 +17185,6 @@ parameters:
 			count: 7
 			path: includes/data-stores/class-wc-product-variation-data-store-cpt.php

-		-
-			message: '#^@param array \$package does not accept actual type of parameter\: object\.$#'
-			identifier: parameter.phpDocType
-			count: 1
-			path: includes/data-stores/class-wc-shipping-zone-data-store.php
-
-		-
-			message: '#^Access to an undefined property object\:\:\$method_id\.$#'
-			identifier: property.notFound
-			count: 1
-			path: includes/data-stores/class-wc-shipping-zone-data-store.php
-
-		-
-			message: '#^Cannot access offset ''destination'' on object\.$#'
-			identifier: offsetAccess.nonOffsetAccessible
-			count: 3
-			path: includes/data-stores/class-wc-shipping-zone-data-store.php
-
 		-
 			message: '#^Method WC_Shipping_Zone_Data_Store\:\:create\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -17593,12 +17299,6 @@ parameters:
 			count: 1
 			path: includes/data-stores/class-wc-webhook-data-store.php

-		-
-			message: '#^Parameter \#2 \$array of function array_map expects array, array\|object given\.$#'
-			identifier: argument.type
-			count: 1
-			path: includes/data-stores/class-wc-webhook-data-store.php
-
 		-
 			message: '#^Method WC_Email_Cancelled_Order\:\:init_form_fields\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -20545,18 +20245,6 @@ parameters:
 			count: 1
 			path: includes/legacy/abstract-wc-legacy-product.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:find_matching_product_variation\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/legacy/abstract-wc-legacy-product.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_related_products_query\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/legacy/abstract-wc-legacy-product.php
-
 		-
 			message: '#^Call to an undefined static method WC_Abstract_Legacy_Product\:\:sync\(\)\.$#'
 			identifier: staticMethod.notFound
@@ -23413,7 +23101,6 @@ parameters:
 			count: 1
 			path: includes/rest-api/Controllers/Version1/class-wc-rest-product-attributes-v1-controller.php

-
 		-
 			message: '#^Method WC_REST_Product_Attributes_V1_Controller\:\:get_items_permissions_check\(\) has parameter \$request with generic class WP_REST_Request but does not specify its types\: T$#'
 			identifier: missingType.generics
@@ -23492,7 +23179,6 @@ parameters:
 			count: 1
 			path: includes/rest-api/Controllers/Version1/class-wc-rest-product-attributes-v1-controller.php

-
 		-
 			message: '#^Cannot access property \$post_date_gmt on WP_Post\|null\.$#'
 			identifier: property.nonObject
@@ -24669,12 +24355,6 @@ parameters:
 			count: 1
 			path: includes/rest-api/Controllers/Version1/class-wc-rest-webhook-deliveries-v1-controller.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:search_webhooks\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/rest-api/Controllers/Version1/class-wc-rest-webhooks-v1-controller.php
-
 		-
 			message: '#^Call to function is_null\(\) with mixed will always evaluate to false\.$#'
 			identifier: function.impossibleType
@@ -28915,12 +28595,6 @@ parameters:
 			count: 2
 			path: includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_related_products\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php
-
 		-
 			message: '#^Call to an undefined method WC_Product\:\:set_button_text\(\)\.$#'
 			identifier: method.notFound
@@ -32077,18 +31751,6 @@ parameters:
 			count: 1
 			path: includes/wc-core-functions.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_code_by_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-coupon-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_ids_by_code\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-coupon-functions.php
-
 		-
 			message: '#^Access to an undefined property WC_Session\:\:\$cart\.$#'
 			identifier: property.notFound
@@ -33313,42 +32975,6 @@ parameters:
 			count: 1
 			path: includes/wc-order-functions.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_by_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_downloads\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_order_id_by_order_key\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_unpaid_orders\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:search_orders\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:update_product_sales\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-functions.php
-
 		-
 			message: '#^Call to an undefined method WC_Order_Item\:\:get_product\(\)\.$#'
 			identifier: method.notFound
@@ -33602,54 +33228,6 @@ parameters:
 			count: 2
 			path: includes/wc-order-functions.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:add_metadata\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-item-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:add_order_item\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-item-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_metadata\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-item-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_order_item\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-item-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_metadata\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-item-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_order_id_by_order_item_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-item-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:update_metadata\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-item-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:update_order_item\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-order-item-functions.php
-
 		-
 			message: '#^Call to an undefined method WC_Order_Item\:\:get_product_id\(\)\.$#'
 			identifier: method.notFound
@@ -33698,60 +33276,6 @@ parameters:
 			count: 1
 			path: includes/wc-page-functions.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_ending_sales\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-product-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_featured_product_ids\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-product-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_on_sale_products\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-product-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_product_id_by_global_unique_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-product-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_product_id_by_sku\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-product-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_related_products\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-product-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_starting_sales\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-product-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:is_existing_global_unique_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-product-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:is_existing_sku\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-product-functions.php
-
 		-
 			message: '#^Call to function is_array\(\) with array\<mixed\> will always evaluate to true\.$#'
 			identifier: function.alreadyNarrowedType
@@ -34011,7 +33535,7 @@ parameters:
 			path: includes/wc-stock-functions.php

 		-
-			message: '#^@param int \$new_stock does not accept actual type of parameter\: bool\|int\|null\.$#'
+			message: '#^@param int \$new_stock does not accept actual type of parameter\: int\|true\|null\.$#'
 			identifier: parameter.phpDocType
 			count: 1
 			path: includes/wc-stock-functions.php
@@ -34022,18 +33546,6 @@ parameters:
 			count: 2
 			path: includes/wc-stock-functions.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:read_stock_quantity\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-stock-functions.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:update_product_stock\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-stock-functions.php
-
 		-
 			message: '#^Call to an undefined method WC_Order_Item\:\:get_product\(\)\.$#'
 			identifier: method.notFound
@@ -34064,24 +33576,6 @@ parameters:
 			count: 2
 			path: includes/wc-stock-functions.php

-		-
-			message: '#^Cannot call method get_stock_quantity\(\) on WC_Product\|false\|null\.$#'
-			identifier: method.nonObject
-			count: 1
-			path: includes/wc-stock-functions.php
-
-		-
-			message: '#^Cannot call method is_type\(\) on WC_Product\|false\|null\.$#'
-			identifier: method.nonObject
-			count: 2
-			path: includes/wc-stock-functions.php
-
-		-
-			message: '#^Cannot call method save\(\) on WC_Product\|false\|null\.$#'
-			identifier: method.nonObject
-			count: 1
-			path: includes/wc-stock-functions.php
-
 		-
 			message: '#^Function wc_get_held_stock_quantity\(\) should return int but returns float\|int\.$#'
 			identifier: return.type
@@ -34815,12 +34309,6 @@ parameters:
 			count: 1
 			path: includes/wc-user-functions.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_downloads_for_customer\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-user-functions.php
-
 		-
 			message: '#^Call to an undefined method WC_Order\|WC_Order_Refund\:\:get_order_key\(\)\.$#'
 			identifier: method.notFound
@@ -34977,12 +34465,6 @@ parameters:
 			count: 1
 			path: includes/wc-user-functions.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_webhooks_ids\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/wc-webhook-functions.php
-
 		-
 			message: '#^Function wc_deliver_webhook_async\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -38445,7 +37927,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/ProductAttributeTerms.php

-
 		-
 			message: '#^Access to offset ''slug'' on an unknown class Automattic\\WooCommerce\\Admin\\API\\WP_REST_Request\.$#'
 			identifier: class.notFound
@@ -38476,9 +37957,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/ProductAttributes.php

-
-
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Admin\\API\\ProductAttributes\:\:register_routes\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -38509,8 +37987,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/ProductAttributes.php

-
-
 		-
 			message: '#^Parameter \#2 \$value of method WP_HTTP_Response\:\:header\(\) expects string, int given\.$#'
 			identifier: argument.type
@@ -38529,8 +38005,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/ProductAttributes.php

-
-
 		-
 			message: '#^PHPDoc tag @extends has invalid value \(WC_REST_Product_Categories_Controller\)\: Unexpected token "\\n ", expected ''\<'' at offset 103 on line 5$#'
 			identifier: phpDoc.parseError
@@ -39221,12 +38695,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Categories/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Categories/Query.php
-
 		-
 			message: '#^@param Automattic\\WooCommerce\\Admin\\API\\Reports\\WP_REST_Response \$response does not accept actual type of parameter\: WP_REST_Response\.$#'
 			identifier: parameter.phpDocType
@@ -39443,12 +38911,6 @@ parameters:
 			count: 2
 			path: src/Admin/API/Reports/Coupons/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Coupons/Query.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Admin\\API\\Reports\\Coupons\\Stats\\Controller\:\:prepare_item_for_response\(\) has parameter \$request with generic class WP_REST_Request but does not specify its types\: T$#'
 			identifier: missingType.generics
@@ -39491,12 +38953,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Coupons/Stats/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Coupons/Stats/Query.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Admin\\API\\Reports\\Coupons\\Stats\\Segmenter\:\:get_segments\(\) should return array but returns array\|null\.$#'
 			identifier: return.type
@@ -39815,12 +39271,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Customers/Stats/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Customers/Stats/Query.php
-
 		-
 			message: '#^Access to offset ''time_interval'' on an unknown class Automattic\\WooCommerce\\Admin\\API\\Reports\\stdClass\.$#'
 			identifier: class.notFound
@@ -40193,12 +39643,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Downloads/Files/Controller.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Downloads/Query.php
-
 		-
 			message: '#^@param object \$report does not accept actual type of parameter\: array\.$#'
 			identifier: parameter.phpDocType
@@ -40235,12 +39679,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Downloads/Stats/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Downloads/Stats/Query.php
-
 		-
 			message: '#^Access to offset ''email'' on an unknown class Automattic\\WooCommerce\\Admin\\API\\Reports\\Export\\WP_REST_Request\.$#'
 			identifier: class.notFound
@@ -41465,12 +40903,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Products/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Products/Query.php
-
 		-
 			message: '#^@param object \$report does not accept actual type of parameter\: array\.$#'
 			identifier: parameter.phpDocType
@@ -41531,12 +40963,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Products/Stats/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Products/Stats/Query.php
-
 		-
 			message: '#^Offset 1 might not exist on array\{\}\|array\{non\-falsy\-string, numeric\-string, numeric\-string\}\.$#'
 			identifier: offsetAccess.notFound
@@ -41555,12 +40981,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Products/Stats/Segmenter.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Revenue/Query.php
-
 		-
 			message: '#^@param object \$report does not accept actual type of parameter\: array\.$#'
 			identifier: parameter.phpDocType
@@ -41927,12 +41347,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Stock/Stats/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Stock/Stats/Query.php
-
 		-
 			message: '#^Access to property \$tax_rate_id on an unknown class Automattic\\WooCommerce\\Admin\\API\\Reports\\Taxes\\WC_Reports_Query\.$#'
 			identifier: class.notFound
@@ -42011,12 +41425,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Taxes/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Taxes/Query.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Admin\\API\\Reports\\Taxes\\Stats\\Controller\:\:prepare_item_for_response\(\) has parameter \$request with generic class WP_REST_Request but does not specify its types\: T$#'
 			identifier: missingType.generics
@@ -42053,12 +41461,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Taxes/Stats/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Taxes/Stats/Query.php
-
 		-
 			message: '#^Call to function is_array\(\) with array\<int, mixed\> will always evaluate to true\.$#'
 			identifier: function.alreadyNarrowedType
@@ -42353,12 +41755,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Variations/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Variations/Query.php
-
 		-
 			message: '#^@param object \$report does not accept actual type of parameter\: array\.$#'
 			identifier: parameter.phpDocType
@@ -42401,12 +41797,6 @@ parameters:
 			count: 1
 			path: src/Admin/API/Reports/Variations/Stats/DataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_data\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/API/Reports/Variations/Stats/Query.php
-
 		-
 			message: '#^Offset 1 might not exist on array\{\}\|array\{non\-falsy\-string, numeric\-string, numeric\-string\}\.$#'
 			identifier: offsetAccess.notFound
@@ -43895,12 +43285,6 @@ parameters:
 			count: 1
 			path: src/Admin/Features/OnboardingTasks/Tasks/Products.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_zones\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Admin/Features/OnboardingTasks/Tasks/Shipping.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Admin\\Features\\OnboardingTasks\\Tasks\\Shipping\:\:delete_zone_count_transient\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -51462,12 +50846,6 @@ parameters:
 			count: 1
 			path: src/Caching/WPCacheEngine.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_query_for_stock\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Checkout/Helpers/ReserveStock.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Checkout\\Helpers\\ReserveStock\:\:release_stock_for_order\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -52627,12 +52005,6 @@ parameters:
 			count: 1
 			path: src/Internal/Admin/FeaturePlugin.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_zones\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Internal/Admin/Homescreen.php
-
 		-
 			message: '#^Call to function method_exists\(\) with ''WC_Admin_Menus'' and ''can_view…'' will always evaluate to true\.$#'
 			identifier: function.alreadyNarrowedType
@@ -53341,12 +52713,6 @@ parameters:
 			count: 1
 			path: src/Internal/Admin/Notes/MarketingJetpack.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_notes_with_name\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Internal/Admin/Notes/MarketingJetpack.php
-
 		-
 			message: '#^Call to function method_exists\(\) with ''Automattic\\\\WooCommerce\\\\Internal\\\\Admin\\\\Notes\\\\MarketingJetpack'' and ''get_note'' will always evaluate to true\.$#'
 			identifier: function.alreadyNarrowedType
@@ -53791,12 +53157,6 @@ parameters:
 			count: 1
 			path: src/Internal/Admin/Notes/TrackingOptIn.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_notes_with_name\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Internal/Admin/Notes/UnsecuredReportFiles.php
-
 		-
 			message: '#^Cannot call method save\(\) on Automattic\\WooCommerce\\Admin\\Notes\\Note\|null\.$#'
 			identifier: method.nonObject
@@ -57715,12 +57075,6 @@ parameters:
 			count: 1
 			path: src/Internal/DataStores/Orders/OrdersTableDataStore.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:update_user_by_order_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Internal/DataStores/Orders/OrdersTableDataStore.php
-
 		-
 			message: '#^Call to an undefined method object\:\:get_current_class_name\(\)\.$#'
 			identifier: method.notFound
@@ -60376,12 +59730,6 @@ parameters:
 			count: 1
 			path: src/Internal/RestApi/Routes/V4/AbstractSchema.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:query_customers\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Internal/RestApi/Routes/V4/Customers/CollectionQuery.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Customers\\CollectionQuery\:\:get_query_args\(\) has parameter \$request with generic class WP_REST_Request but does not specify its types\: T$#'
 			identifier: missingType.generics
@@ -60862,12 +60210,6 @@ parameters:
 			count: 1
 			path: src/Internal/RestApi/Routes/V4/OrderNotes/Schema/OrderNoteSchema.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:delete_by_order_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Internal/RestApi/Routes/V4/Orders/ActionController.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Orders\\ActionController\:\:action_payment_complete\(\) has parameter \$request with generic class WP_REST_Request but does not specify its types\: T$#'
 			identifier: missingType.generics
@@ -62892,12 +62234,6 @@ parameters:
 			count: 1
 			path: src/Internal/RestApi/Routes/V4/ShippingZoneMethod/ShippingMethodSchema.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_zone_id_by_instance_id\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Internal/RestApi/Routes/V4/ShippingZoneMethod/ShippingMethodSchema.php
-
 		-
 			message: '#^Call to an undefined method object\:\:get_title\(\)\.$#'
 			identifier: method.notFound
@@ -63210,48 +62546,12 @@ parameters:
 			count: 1
 			path: src/Internal/RestockRefundedItemsAdjuster.php

-		-
-			message: '#^Binary operation "/" between array\<Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|int\>\|int and int\<1, max\> results in an error\.$#'
-			identifier: binaryOp.invalid
-			count: 1
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:query\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
-		-
-			message: '#^Cannot call method set_status\(\) on Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|bool\.$#'
-			identifier: method.nonObject
-			count: 2
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Internal\\StockNotifications\\Admin\\ListTable\:\:init\(\) has no return type specified\.$#'
 			identifier: missingType.return
 			count: 1
 			path: src/Internal/StockNotifications/Admin/ListTable.php

-		-
-			message: '#^Parameter \#1 \$args of method WP_List_Table\:\:set_pagination_args\(\) expects array\{total_items\?\: int, total_pages\?\: int, per_page\?\: int\}, array\{total_items\: array\<Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|int\>\|int, per_page\: int\<1, max\>, total_pages\: \(float\|false\)\} given\.$#'
-			identifier: argument.type
-			count: 1
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
-		-
-			message: '#^Parameter \#1 \$notification of method Automattic\\WooCommerce\\Internal\\DataStores\\StockNotifications\\StockNotificationsDataStore\:\:delete\(\) expects Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification, Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|bool given\.$#'
-			identifier: argument.type
-			count: 2
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
-		-
-			message: '#^Parameter \#1 \$notification of method Automattic\\WooCommerce\\Internal\\DataStores\\StockNotifications\\StockNotificationsDataStore\:\:update\(\) expects Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification, Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|bool given\.$#'
-			identifier: argument.type
-			count: 2
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
 		-
 			message: '#^Parameter \#1 \$object_or_string of function is_a expects object, WC_Product\|false given\.$#'
 			identifier: argument.type
@@ -63282,48 +62582,6 @@ parameters:
 			count: 1
 			path: src/Internal/StockNotifications/Admin/ListTable.php

-		-
-			message: '#^Property Automattic\\WooCommerce\\Internal\\StockNotifications\\Admin\\ListTable\:\:\$data_store \(Automattic\\WooCommerce\\Internal\\DataStores\\StockNotifications\\StockNotificationsDataStore\) does not accept WC_Data_Store\.$#'
-			identifier: assign.propertyType
-			count: 1
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
-		-
-			message: '#^Property Automattic\\WooCommerce\\Internal\\StockNotifications\\Admin\\ListTable\:\:\$total_active_items \(int\) does not accept array\<Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|int\>\|int\.$#'
-			identifier: assign.propertyType
-			count: 1
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
-		-
-			message: '#^Property Automattic\\WooCommerce\\Internal\\StockNotifications\\Admin\\ListTable\:\:\$total_cancelled_items \(int\) does not accept array\<Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|int\>\|int\.$#'
-			identifier: assign.propertyType
-			count: 1
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
-		-
-			message: '#^Property Automattic\\WooCommerce\\Internal\\StockNotifications\\Admin\\ListTable\:\:\$total_items \(int\) does not accept array\<Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|int\>\|int\.$#'
-			identifier: assign.propertyType
-			count: 1
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
-		-
-			message: '#^Property Automattic\\WooCommerce\\Internal\\StockNotifications\\Admin\\ListTable\:\:\$total_pending_items \(int\) does not accept array\<Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|int\>\|int\.$#'
-			identifier: assign.propertyType
-			count: 1
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
-		-
-			message: '#^Property Automattic\\WooCommerce\\Internal\\StockNotifications\\Admin\\ListTable\:\:\$total_sent_items \(int\) does not accept array\<Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|int\>\|int\.$#'
-			identifier: assign.propertyType
-			count: 1
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
-		-
-			message: '#^Property WP_List_Table\:\:\$items \(array\) does not accept array\<Automattic\\WooCommerce\\Internal\\StockNotifications\\Notification\|int\>\|int\.$#'
-			identifier: assign.propertyType
-			count: 1
-			path: src/Internal/StockNotifications/Admin/ListTable.php
-
 		-
 			message: '#^Action callback returns bool\|void but should not return anything\.$#'
 			identifier: return.void
@@ -63336,12 +62594,6 @@ parameters:
 			count: 1
 			path: src/Internal/StockNotifications/Admin/MenusController.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:query\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Internal/StockNotifications/Admin/NotificationCreatePage.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Internal\\StockNotifications\\Admin\\NotificationCreatePage\:\:output\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -64062,12 +63314,6 @@ parameters:
 			count: 1
 			path: src/Internal/Utilities/ArrayUtil.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:get_order_type\(\)\.$#'
-			identifier: method.notFound
-			count: 2
-			path: src/Internal/Utilities/COTMigrationUtil.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Internal\\Utilities\\COTMigrationUtil\:\:get_post_or_order_id\(\) has parameter \$post_or_order_object with no type specified\.$#'
 			identifier: missingType.parameter
@@ -64278,12 +63524,6 @@ parameters:
 			count: 1
 			path: src/Internal/Utilities/Users.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:search_webhooks\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/Internal/Utilities/WebhookUtil.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Packages\:\:deactivate_merged_packages\(\) has no return type specified\.$#'
 			identifier: missingType.return
@@ -66324,12 +65564,6 @@ parameters:
 			count: 1
 			path: src/StoreApi/Utilities/CartController.php

-		-
-			message: '#^Call to an undefined method WC_Data_Store\:\:find_matching_product_variation\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: src/StoreApi/Utilities/CartController.php
-
 		-
 			message: '#^Cannot call method get_id\(\) on WC_Product\|false\|null\.$#'
 			identifier: method.nonObject
diff --git a/plugins/woocommerce/phpstan.neon b/plugins/woocommerce/phpstan.neon
index 9dd8735e055..099359d8b93 100644
--- a/plugins/woocommerce/phpstan.neon
+++ b/plugins/woocommerce/phpstan.neon
@@ -1,6 +1,7 @@
 includes:
 	- phpstan-baseline.neon
 	- vendor/szepeviktor/phpstan-wordpress/extension.neon
+	- tests/Tools/phpstan/extensions.neon

 parameters:
 	tmpDir: tmp
diff --git a/plugins/woocommerce/src/Admin/API/Reports/Stock/Stats/Query.php b/plugins/woocommerce/src/Admin/API/Reports/Stock/Stats/Query.php
index b4886e62340..5cb3c7cf6be 100644
--- a/plugins/woocommerce/src/Admin/API/Reports/Stock/Stats/Query.php
+++ b/plugins/woocommerce/src/Admin/API/Reports/Stock/Stats/Query.php
@@ -23,7 +23,7 @@ class Query extends \WC_Object_Query {
 	 */
 	public function get_data() {
 		$data_store = \WC_Data_Store::load( 'report-stock-stats' );
-		$results    = $data_store->get_data();
+		$results    = $data_store->get_data( array() );
 		return apply_filters( 'woocommerce_analytics_stock_stats_query', $results );
 	}
 }
diff --git a/plugins/woocommerce/src/Internal/DataStores/StockNotifications/StockNotificationsDataStore.php b/plugins/woocommerce/src/Internal/DataStores/StockNotifications/StockNotificationsDataStore.php
index 93d4d309a37..68c1a780d01 100644
--- a/plugins/woocommerce/src/Internal/DataStores/StockNotifications/StockNotificationsDataStore.php
+++ b/plugins/woocommerce/src/Internal/DataStores/StockNotifications/StockNotificationsDataStore.php
@@ -470,6 +470,8 @@ CREATE TABLE $meta_table_name (
 	 *
 	 * @param array $args The arguments.
 	 * @return array<int>|array<Notification>|int An array of notifications or the number of notifications.
+	 *
+	 * @phpstan-return ($args is array{return: 'count'} ? int : array<int>|array<Notification>)
 	 */
 	public function query( array $args ) {
 		global $wpdb;
diff --git a/plugins/woocommerce/src/Internal/ProductVariations/SelectedVariationName.php b/plugins/woocommerce/src/Internal/ProductVariations/SelectedVariationName.php
index 3b813091135..927dc1586bb 100644
--- a/plugins/woocommerce/src/Internal/ProductVariations/SelectedVariationName.php
+++ b/plugins/woocommerce/src/Internal/ProductVariations/SelectedVariationName.php
@@ -53,7 +53,6 @@ class SelectedVariationName {
 			return $product_name;
 		}

-		// @phpstan-ignore method.notFound (the call is proxied by WC_Data_Store::__call() and guarded by has_callable() above)
 		if ( ! $data_store->should_include_attributes_in_title( $product ) ) {
 			return $product_name;
 		}
diff --git a/plugins/woocommerce/src/Internal/RestApi/Routes/V4/Products/Controller.php b/plugins/woocommerce/src/Internal/RestApi/Routes/V4/Products/Controller.php
index a2fecb075e7..d0dc97b1bb5 100644
--- a/plugins/woocommerce/src/Internal/RestApi/Routes/V4/Products/Controller.php
+++ b/plugins/woocommerce/src/Internal/RestApi/Routes/V4/Products/Controller.php
@@ -2522,8 +2522,7 @@ class Controller extends WC_REST_Products_V2_Controller {
 		$exclude_ids = $request->get_param( 'exclude' );
 		$limit       = $request->get_param( 'limit' ) ? $request->get_param( 'limit' ) : 5;

-		$data_store = WC_Data_Store::load( 'product' );
-		// @phpstan-ignore-next-line method.notFound
+		$data_store                   = WC_Data_Store::load( 'product' );
 		$this->suggested_products_ids = $data_store->get_related_products(
 			$categories,
 			$tags,
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Admin/ListTable.php b/plugins/woocommerce/src/Internal/StockNotifications/Admin/ListTable.php
index 7c616190d17..a0eaeab556a 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Admin/ListTable.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Admin/ListTable.php
@@ -63,7 +63,7 @@ class ListTable extends \WP_List_Table {
 	/**
 	 * Data store.
 	 *
-	 * @var StockNotificationsDataStore
+	 * @var \WC_Data_Store<StockNotificationsDataStore>
 	 */
 	public $data_store;

@@ -425,7 +425,7 @@ class ListTable extends \WP_List_Table {
 			array(
 				'total_items' => $this->total_items, // Total items defined above.
 				'per_page'    => $per_page, // Per page constant defined at top of method.
-				'total_pages' => ceil( $this->total_items / $per_page ), // Calculate pages count.
+				'total_pages' => (int) ceil( $this->total_items / $per_page ), // Calculate pages count.
 			)
 		);
 	}
@@ -726,11 +726,14 @@ class ListTable extends \WP_List_Table {
 		try {

 			$notification = Factory::get_notification( $notification_id );
-			$this->data_store->delete( $notification );
-
-			$notice_message = __( 'Notification deleted.', 'woocommerce' );
-			NotificationsPage::add_notice( $notice_message, 'success' );
+			if ( $notification instanceof Notification ) {
+				$this->data_store->delete( $notification );

+				$notice_message = __( 'Notification deleted.', 'woocommerce' );
+				NotificationsPage::add_notice( $notice_message, 'success' );
+			} else {
+				NotificationsPage::add_notice( __( 'Notification not found.', 'woocommerce' ), 'error' );
+			}
 		} catch ( \Exception $e ) {

 			$notice_message = __( 'Notification not found.', 'woocommerce' );
@@ -761,68 +764,87 @@ class ListTable extends \WP_List_Table {

 		$redirect_url = NotificationsPage::PAGE_URL;

+		$processed = 0;
+
 		if ( 'enable' === $this->current_action() ) {
 			foreach ( $notifications as $id ) {

 				$notification = Factory::get_notification( $id );
+				if ( ! $notification instanceof Notification ) {
+					continue;
+				}
 				$notification->set_status( NotificationStatus::ACTIVE );
 				$this->data_store->update( $notification );
+				++$processed;

 			}
-			$notice_message = sprintf(
-				/* translators: %s: Notifications count */
-				_nx(
-					'%s notification updated.',
-					'%s notifications updated.',
-					count( $notifications ),
-					'notifications_status',
-					'woocommerce'
-				),
-				count( $notifications )
-			);

-			NotificationsPage::add_notice( $notice_message, 'success' );
+			if ( $processed > 0 ) {
+				$notice_message = sprintf(
+					/* translators: %s: Notifications count */
+					_nx(
+						'%s notification updated.',
+						'%s notifications updated.',
+						$processed,
+						'notifications_status',
+						'woocommerce'
+					),
+					$processed
+				);

+				NotificationsPage::add_notice( $notice_message, 'success' );
+			}
 		} elseif ( 'cancel' === $this->current_action() ) {
 			foreach ( $notifications as $id ) {
 				$notification = Factory::get_notification( $id );
+				if ( ! $notification instanceof Notification ) {
+					continue;
+				}
 				$notification->set_status( NotificationStatus::CANCELLED );
 				$this->data_store->update( $notification );
+				++$processed;
 			}

-			$notice_message = sprintf(
-				/* translators: %s: Notifications count */
-				_nx(
-					'%s notification updated.',
-					'%s notifications updated.',
-					count( $notifications ),
-					'notifications_status',
-					'woocommerce'
-				),
-				count( $notifications )
-			);
-
-			NotificationsPage::add_notice( $notice_message, 'success' );
+			if ( $processed > 0 ) {
+				$notice_message = sprintf(
+					/* translators: %s: Notifications count */
+					_nx(
+						'%s notification updated.',
+						'%s notifications updated.',
+						$processed,
+						'notifications_status',
+						'woocommerce'
+					),
+					$processed
+				);

+				NotificationsPage::add_notice( $notice_message, 'success' );
+			}
 		} elseif ( 'delete' === $this->current_action() ) {
 			foreach ( $notifications as $id ) {
 				$notification = Factory::get_notification( $id );
+				if ( ! $notification instanceof Notification ) {
+					continue;
+				}
 				$this->data_store->delete( $notification );
+				++$processed;
 			}

-			$notice_message = sprintf(
-				/* translators: %s: Notifications count */
-				_nx(
-					'%s notification deleted.',
-					'%s notifications deleted.',
-					count( $notifications ),
-					'notifications_status',
-					'woocommerce'
-				),
-				count( $notifications )
-			);
+			if ( $processed > 0 ) {
+				$notice_message = sprintf(
+					/* translators: %s: Notifications count */
+					_nx(
+						'%s notification deleted.',
+						'%s notifications deleted.',
+						$processed,
+						'notifications_status',
+						'woocommerce'
+					),
+					$processed
+				);

-			NotificationsPage::add_notice( $notice_message, 'success' );
+				NotificationsPage::add_notice( $notice_message, 'success' );
+			}
 		}

 		wp_safe_redirect( $redirect_url );
diff --git a/plugins/woocommerce/src/StoreApi/Utilities/OrderController.php b/plugins/woocommerce/src/StoreApi/Utilities/OrderController.php
index 178419581af..9a7b57ed53d 100644
--- a/plugins/woocommerce/src/StoreApi/Utilities/OrderController.php
+++ b/plugins/woocommerce/src/StoreApi/Utilities/OrderController.php
@@ -1107,7 +1107,6 @@ class OrderController {
 		global $wpdb;
 		$data_store = $coupon->get_data_store();
 		if ( $data_store instanceof \WC_Data_Store && $data_store->has_callable( 'add_recorded_user_ids_to_aliases' ) ) {
-			// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the coupon data store instance.)
 			$aliases = $data_store->add_recorded_user_ids_to_aliases( $coupon, $aliases );
 		}
 		$aliases        = array_unique( array_filter( $aliases ) );
diff --git a/plugins/woocommerce/tests/Tools/phpstan/DataStoreHasCallableExtension.php b/plugins/woocommerce/tests/Tools/phpstan/DataStoreHasCallableExtension.php
new file mode 100644
index 00000000000..800baf616fc
--- /dev/null
+++ b/plugins/woocommerce/tests/Tools/phpstan/DataStoreHasCallableExtension.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * DataStoreHasCallableExtension class file.
+ *
+ * @package WooCommerce\Tests
+ */
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\Testing\Tools\phpstan;
+
+use PhpParser\Node\Expr\MethodCall;
+use PHPStan\Analyser\Scope;
+use PHPStan\Analyser\SpecifiedTypes;
+use PHPStan\Analyser\TypeSpecifier;
+use PHPStan\Analyser\TypeSpecifierAwareExtension;
+use PHPStan\Analyser\TypeSpecifierContext;
+use PHPStan\Reflection\MethodReflection;
+use PHPStan\Type\Accessory\HasMethodType;
+use PHPStan\Type\IntersectionType;
+use PHPStan\Type\MethodTypeSpecifyingExtension;
+use PHPStan\Type\ObjectWithoutClassType;
+
+/**
+ * Treats WC_Data_Store::has_callable( 'name' ) like method_exists(): where it returns true, the data store is known to
+ * have that method. This lets code call an optional data store method, which a custom store may not implement, after
+ * checking for it, and still reports the call when the check is missing.
+ */
+final class DataStoreHasCallableExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension {
+
+	/**
+	 * Type specifier.
+	 *
+	 * @var TypeSpecifier
+	 */
+	private $type_specifier;
+
+	/**
+	 * Set the type specifier.
+	 *
+	 * @param TypeSpecifier $type_specifier Type specifier.
+	 */
+	public function setTypeSpecifier( TypeSpecifier $type_specifier ): void {
+		$this->type_specifier = $type_specifier;
+	}
+
+	/**
+	 * Class whose method this extension handles.
+	 *
+	 * @return string
+	 */
+	public function getClass(): string {
+		return 'WC_Data_Store';
+	}
+
+	/**
+	 * Handle has_callable() calls with an argument, where the call is true.
+	 *
+	 * @param MethodReflection     $method_reflection Called method.
+	 * @param MethodCall           $node              Method call node.
+	 * @param TypeSpecifierContext $context           Context of the call.
+	 * @return bool
+	 */
+	public function isMethodSupported( MethodReflection $method_reflection, MethodCall $node, TypeSpecifierContext $context ): bool {
+		return 'has_callable' === $method_reflection->getName() && $context->true() && count( $node->getArgs() ) > 0;
+	}
+
+	/**
+	 * Add the named method to the type of the data store, when the name is a single known string.
+	 *
+	 * @param MethodReflection     $method_reflection Called method.
+	 * @param MethodCall           $node              Method call node.
+	 * @param Scope                $scope             Scope of the call.
+	 * @param TypeSpecifierContext $context           Context of the call.
+	 * @return SpecifiedTypes
+	 */
+	public function specifyTypes( MethodReflection $method_reflection, MethodCall $node, Scope $scope, TypeSpecifierContext $context ): SpecifiedTypes {
+		$method_names = $scope->getType( $node->getArgs()[0]->value )->getConstantStrings();
+		if ( 1 !== count( $method_names ) ) {
+			return new SpecifiedTypes();
+		}
+
+		return $this->type_specifier->create(
+			$node->var,
+			new IntersectionType( array( new ObjectWithoutClassType(), new HasMethodType( $method_names[0]->getValue() ) ) ),
+			$context,
+			$scope
+		);
+	}
+}
diff --git a/plugins/woocommerce/tests/Tools/phpstan/DataStoreHasCallableExtensionTest.php b/plugins/woocommerce/tests/Tools/phpstan/DataStoreHasCallableExtensionTest.php
new file mode 100644
index 00000000000..68f08ab6dda
--- /dev/null
+++ b/plugins/woocommerce/tests/Tools/phpstan/DataStoreHasCallableExtensionTest.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * DataStoreHasCallableExtensionTest class file.
+ *
+ * @package WooCommerce\Tests
+ */
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\Testing\Tools\phpstan;
+
+use PHPStan\Testing\TypeInferenceTestCase;
+
+/**
+ * Tests for DataStoreHasCallableExtension.
+ */
+final class DataStoreHasCallableExtensionTest extends TypeInferenceTestCase {
+
+	/**
+	 * @testdox A true has_callable() check with a known method name adds that method to the data store type.
+	 */
+	public function test_has_callable_narrows_the_data_store_type(): void {
+		foreach ( self::gatherAssertTypes( __DIR__ . '/data/has-callable.php' ) as $assertion ) {
+			$this->assertFileAsserts( ...$assertion );
+		}
+	}
+
+	/**
+	 * Config that registers the extension.
+	 *
+	 * @return string[]
+	 */
+	public static function getAdditionalConfigFiles(): array {
+		return array( __DIR__ . '/extensions.neon' );
+	}
+}
diff --git a/plugins/woocommerce/tests/Tools/phpstan/bootstrap.php b/plugins/woocommerce/tests/Tools/phpstan/bootstrap.php
new file mode 100644
index 00000000000..55ebca4faf0
--- /dev/null
+++ b/plugins/woocommerce/tests/Tools/phpstan/bootstrap.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Bootstrap for the PHPStan extension tests. PHPStan reflects test fixtures only through registered autoloaders.
+ *
+ * @package WooCommerce\Tests
+ */
+
+declare( strict_types=1 );
+
+require_once __DIR__ . '/../../../vendor/autoload.php';
+
+spl_autoload_register(
+	function ( string $class_name ): void {
+		if ( 'WC_Data_Store' === $class_name ) {
+			require_once __DIR__ . '/data/stubs.php';
+		}
+	}
+);
diff --git a/plugins/woocommerce/tests/Tools/phpstan/data/has-callable.php b/plugins/woocommerce/tests/Tools/phpstan/data/has-callable.php
new file mode 100644
index 00000000000..79201da9c56
--- /dev/null
+++ b/plugins/woocommerce/tests/Tools/phpstan/data/has-callable.php
@@ -0,0 +1,26 @@
+<?php
+
+use function PHPStan\Testing\assertType;
+
+function has_callable_in_if( WC_Data_Store $store ): void {
+	if ( $store->has_callable( 'get_orders_type' ) ) {
+		assertType( 'WC_Data_Store&hasMethod(get_orders_type)', $store );
+	}
+	assertType( 'WC_Data_Store', $store );
+}
+
+function has_callable_in_and( WC_Data_Store $store ): void {
+	$store->has_callable( 'delete_items_by_ids' ) && assertType( 'WC_Data_Store&hasMethod(delete_items_by_ids)', $store );
+}
+
+function has_callable_negated( WC_Data_Store $store ): void {
+	if ( ! $store->has_callable( 'get_orders_type' ) ) {
+		assertType( 'WC_Data_Store', $store );
+	}
+}
+
+function has_callable_with_unknown_name( WC_Data_Store $store, string $method ): void {
+	if ( $store->has_callable( $method ) ) {
+		assertType( 'WC_Data_Store', $store );
+	}
+}
diff --git a/plugins/woocommerce/tests/Tools/phpstan/data/stubs.php b/plugins/woocommerce/tests/Tools/phpstan/data/stubs.php
new file mode 100644
index 00000000000..ff62571fe96
--- /dev/null
+++ b/plugins/woocommerce/tests/Tools/phpstan/data/stubs.php
@@ -0,0 +1,7 @@
+<?php
+
+class WC_Data_Store {
+	public function has_callable( string $method ): bool {
+		return true;
+	}
+}
diff --git a/plugins/woocommerce/tests/Tools/phpstan/extensions.neon b/plugins/woocommerce/tests/Tools/phpstan/extensions.neon
new file mode 100644
index 00000000000..ca9cd96450b
--- /dev/null
+++ b/plugins/woocommerce/tests/Tools/phpstan/extensions.neon
@@ -0,0 +1,5 @@
+services:
+	-
+		class: Automattic\WooCommerce\Testing\Tools\phpstan\DataStoreHasCallableExtension
+		tags:
+			- phpstan.typeSpecifier.methodTypeSpecifyingExtension
diff --git a/plugins/woocommerce/tests/Tools/phpstan/phpunit.xml b/plugins/woocommerce/tests/Tools/phpstan/phpunit.xml
new file mode 100644
index 00000000000..e9211befcb4
--- /dev/null
+++ b/plugins/woocommerce/tests/Tools/phpstan/phpunit.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	bootstrap="bootstrap.php"
+	colors="true"
+	xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
+	<testsuites>
+		<testsuite name="phpstan-rules">
+			<directory suffix="Test.php">.</directory>
+		</testsuite>
+	</testsuites>
+</phpunit>
diff --git a/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-products-test.php b/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-products-test.php
index 94c67aeb568..e7343b52877 100644
--- a/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-products-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-products-test.php
@@ -87,6 +87,26 @@ class WC_Admin_List_Table_Products_Test extends WC_Unit_Test_Case {
 		);
 	}

+	/**
+	 * @testdox Product searches return no products for a term that is empty after sanitizing, including a term that is not a string.
+	 */
+	public function test_product_search_returns_no_products_for_empty_term(): void {
+		WC_Helper_Product::create_simple_product();
+
+		foreach ( array( '<br>', array( 'foo' ) ) as $search_term ) {
+			$query_vars = $this->sut->request_query(
+				array(
+					'post_type'   => 'product',
+					'post_status' => 'publish',
+					'fields'      => 'ids',
+					's'           => $search_term,
+				)
+			);
+
+			$this->assertSame( array(), ( new WP_Query( $query_vars ) )->get_posts(), 'The search term ' . wp_json_encode( $search_term ) . ' should match no products' );
+		}
+	}
+
 	/**
 	 * @testdox Product searches return a partial title match.
 	 */
diff --git a/plugins/woocommerce/tests/php/includes/wc-order-functions-test.php b/plugins/woocommerce/tests/php/includes/wc-order-functions-test.php
index cb157a185a2..108f36bb38e 100644
--- a/plugins/woocommerce/tests/php/includes/wc-order-functions-test.php
+++ b/plugins/woocommerce/tests/php/includes/wc-order-functions-test.php
@@ -1401,6 +1401,16 @@ class WC_Order_Functions_Test extends \WC_Unit_Test_Case {
 		$this->assertSame( array( $products['kept']->get_id() ), $this->get_download_permission_product_ids( $order ), 'Regenerating the downloads should give a download only for the line that was not refunded.' );
 	}

+	/**
+	 * @testdox wc_order_search() returns no orders for a term that is empty after sanitizing, including a term that is not a string.
+	 */
+	public function test_wc_order_search_returns_no_orders_for_empty_term(): void {
+		WC_Helper_Order::create_order();
+
+		$this->assertSame( array(), wc_order_search( '<br>' ), 'A term with only a tag should match no orders' );
+		$this->assertSame( array(), wc_order_search( array( 'foo' ) ), 'An array term should match no orders' );
+	}
+
 	/**
 	 * Get the product IDs of an order's download permissions.
 	 *
diff --git a/plugins/woocommerce/tests/php/includes/wc-stock-functions-tests.php b/plugins/woocommerce/tests/php/includes/wc-stock-functions-tests.php
index 5d190f228a1..23e93058e6e 100644
--- a/plugins/woocommerce/tests/php/includes/wc-stock-functions-tests.php
+++ b/plugins/woocommerce/tests/php/includes/wc-stock-functions-tests.php
@@ -954,4 +954,59 @@ class WC_Stock_Functions_Tests extends \WC_Unit_Test_Case {
 		$this->assertSame( 6, $product->get_stock_quantity() );
 		$this->assertGreaterThan( strtotime( $past ), $product->get_date_modified()->getTimestamp() );
 	}
+
+	/**
+	 * @testdox Stock updates and order stock bookkeeping are skipped when the product that manages the stock cannot be loaded.
+	 */
+	public function test_stock_changes_are_skipped_when_stock_owner_cannot_be_loaded(): void {
+		$parent = WC_Helper_Product::create_variation_product();
+		$parent->set_manage_stock( true );
+		$parent->set_stock_quantity( 10 );
+		$parent->save();
+
+		$variation = wc_get_product( $parent->get_children()[0] );
+		$order     = WC_Helper_Order::create_order( 0, $variation );
+		$this->assertSame( $parent->get_id(), $variation->get_stock_managed_by_id(), 'The variation should take its stock from the parent' );
+
+		// A post type other than product makes wc_get_product() return false for the parent.
+		$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, array( 'post_type' => 'post' ), array( 'ID' => $parent->get_id() ) );
+		clean_post_cache( $parent->get_id() );
+
+		$this->assertFalse( wc_update_product_stock( $variation, 5 ), 'The update should fail when the parent cannot be loaded' );
+
+		// Reading the variation again would drop its invalid parent, so hand the order item the variation loaded above.
+		$return_variation = function () use ( $variation ) {
+			return $variation;
+		};
+		add_filter( 'woocommerce_order_item_product', $return_variation );
+
+		wc_reduce_stock_levels( $order );
+		$item  = current( $order->get_items() );
+		$notes = wc_get_order_notes( array( 'order_id' => $order->get_id() ) );
+		$this->assertSame( '', $item->get_meta( '_reduced_stock', true ), 'Reducing should not mark the item as reduced' );
+		$this->assertStringStartsWith( 'Unable to reduce stock for item', $notes[0]->content, 'Reducing should add an error note' );
+
+		$item->add_meta_data( '_reduced_stock', 4, true );
+		$item->save();
+		wc_increase_stock_levels( $order );
+		$item  = current( $order->get_items() );
+		$notes = wc_get_order_notes( array( 'order_id' => $order->get_id() ) );
+		$this->assertSame( '4', (string) $item->get_meta( '_reduced_stock', true ), 'Restoring should keep the item marked as reduced' );
+		$this->assertStringStartsWith( 'Unable to restore stock for item', $notes[0]->content, 'Restoring should add an error note' );
+
+		$note_count = count( $notes );
+		wc_restock_refunded_items( $order, array( $item->get_id() => array( 'qty' => 1 ) ) );
+		$item  = current( $order->get_items() );
+		$notes = wc_get_order_notes( array( 'order_id' => $order->get_id() ) );
+		$this->assertSame( '4', (string) $item->get_meta( '_reduced_stock', true ), 'Restocking a refund should keep the item marked as reduced' );
+		$this->assertSame( '', $item->get_meta( '_restock_refunded_items', true ), 'Restocking a refund should not count the item as restocked' );
+		$this->assertCount( $note_count + 1, $notes, 'Restocking a refund should add one note' );
+		$this->assertStringStartsWith( 'Unable to restore stock for item', $notes[0]->content, 'Restocking a refund should add an error note' );
+
+		$this->assertFalse( wc_maybe_adjust_line_item_product_stock( $item, 6 ), 'Adjusting the line item stock should report no change' );
+		$this->assertSame( '4', (string) $item->get_meta( '_reduced_stock', true ), 'Adjusting the line item stock should keep the reduced quantity' );
+
+		remove_filter( 'woocommerce_order_item_product', $return_variation );
+		$this->assertSame( '10', get_post_meta( $parent->get_id(), '_stock', true ), 'The parent stock should not change' );
+	}
 }