From 9339cac2023c5f82ad6e014395e71c91ba3a3dbd Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 19 Nov 2025 10:02:58 -0700 Subject: [PATCH 1/9] Use strings instead of class properties --- .../sync/src/modules/class-woocommerce-products.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/projects/packages/sync/src/modules/class-woocommerce-products.php b/projects/packages/sync/src/modules/class-woocommerce-products.php index df01192797d28..f3a499b6051d7 100644 --- a/projects/packages/sync/src/modules/class-woocommerce-products.php +++ b/projects/packages/sync/src/modules/class-woocommerce-products.php @@ -7,7 +7,6 @@ namespace Automattic\Jetpack\Sync\Modules; -use Automattic\WooCommerce\Enums\ProductType; use DateTimeZone; use WC_DateTime; use WP_Error; @@ -292,10 +291,12 @@ public function get_product_by_ids( $ids, $order = '' ) { ); $post_type = $post->post_type; + // ProductType::VARIATION and ProductType::SIMPLE have only existed since WooCommerce 9.7, so + // we can't rely on that existing, but using the strings is probably safe enough. if ( 'product_variation' === $post_type ) { - $product_type = ProductType::VARIATION; + $product_type = 'variation'; } elseif ( 'product' === $post_type ) { - $product_type = $product_types[ $post->ID ] ?? ProductType::SIMPLE; + $product_type = $product_types[ $post->ID ] ?? 'simple'; } else { $product_type = null; } From 4bcb8d65e9111feb41b575f7a70d70a3b596aaff Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 19 Nov 2025 10:49:20 -0700 Subject: [PATCH 2/9] Add check for method and suppress Phan --- .../packages/sync/src/modules/class-woocommerce-products.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/packages/sync/src/modules/class-woocommerce-products.php b/projects/packages/sync/src/modules/class-woocommerce-products.php index f3a499b6051d7..9d5219a20b6db 100644 --- a/projects/packages/sync/src/modules/class-woocommerce-products.php +++ b/projects/packages/sync/src/modules/class-woocommerce-products.php @@ -445,7 +445,8 @@ private function get_product_posts( $ids, $order = '' ) { * @return array */ private function get_product_cogs_data( $ids, $order = '' ) { - $is_cogs_enabled = class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'cost_of_goods_sold' ); + // @phan-suppress-next-line PhanUndeclaredClassReference, PhanUndeclaredClassMethod -- we're checking for the class and method before using them. + $is_cogs_enabled = class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && method_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil', 'feature_is_enabled' ) && \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'cost_of_goods_sold' ); if ( ! $is_cogs_enabled ) { return array(); From 7524f8b3189c11a6033311cdb3a68a2b7ca1099c Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 19 Nov 2025 10:49:30 -0700 Subject: [PATCH 3/9] Suppress Phan --- .../woocommerce-analytics/src/class-wc-analytics-tracking.php | 1 + .../woocommerce-analytics/src/class-woo-analytics-trait.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php b/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php index 79f2774ae1ddd..9f17c5d0ef56a 100644 --- a/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php +++ b/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php @@ -231,6 +231,7 @@ public static function send_batched_pixels() { foreach ( self::$pixel_batch_queue as $pixel ) { // Check if the method exists for backwards compatibility with older WooCommerce versions. if ( method_exists( WC_Tracks_Client::class, 'add_request_timestamp_and_nocache' ) ) { + // @phan-suppress-next-line PhanUndeclaredStaticMethod -- We verify the method exists before using it. $pixels_to_send[] = WC_Tracks_Client::add_request_timestamp_and_nocache( $pixel ); } else { // Fallback for older versions - add timestamp and nocache parameters manually. diff --git a/projects/packages/woocommerce-analytics/src/class-woo-analytics-trait.php b/projects/packages/woocommerce-analytics/src/class-woo-analytics-trait.php index 26c69b221e82a..3f85751567765 100644 --- a/projects/packages/woocommerce-analytics/src/class-woo-analytics-trait.php +++ b/projects/packages/woocommerce-analytics/src/class-woo-analytics-trait.php @@ -172,6 +172,7 @@ public function find_cart_checkout_content_sources() { $this->cart_checkout_templates_in_use = wp_is_block_theme() && class_exists( '\Automattic\WooCommerce\Blocks\Package' ) + // @phan-suppress-next-line PhanUndeclaredClassMethod -- If the class exists (as of WooCommerce 8.5.0), the method exists. && version_compare( \Automattic\WooCommerce\Blocks\Package::get_version(), '10.6.0', '>=' ); // Cart/Checkout *pages* are in use if the templates are not in use. Return their content and do nothing else. @@ -260,6 +261,7 @@ public function find_cart_checkout_content_sources() { public function get_common_properties() { $site_info = array( 'blog_id' => Jetpack_Connection::get_site_id(), + // @phan-suppress-next-line PhanUndeclaredConstantOfClass -- The constant has only existed since WooCommerce 8.4, but we check for its existence. 'store_id' => defined( '\\WC_Install::STORE_ID_OPTION' ) ? get_option( \WC_Install::STORE_ID_OPTION ) : false, 'ui' => $this->get_user_id(), 'url' => home_url(), From 87f82800454e88b52391c4caa5eff6fdafb59f5d Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 19 Nov 2025 10:50:35 -0700 Subject: [PATCH 4/9] Add changelogs --- projects/packages/sync/changelog/fix-phan-issues_in_old_woo | 4 ++++ .../changelog/fix-phan-issues_in_old_woo | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 projects/packages/sync/changelog/fix-phan-issues_in_old_woo create mode 100644 projects/packages/woocommerce-analytics/changelog/fix-phan-issues_in_old_woo diff --git a/projects/packages/sync/changelog/fix-phan-issues_in_old_woo b/projects/packages/sync/changelog/fix-phan-issues_in_old_woo new file mode 100644 index 0000000000000..a08476d53b87e --- /dev/null +++ b/projects/packages/sync/changelog/fix-phan-issues_in_old_woo @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Improve compatibility with old WooCommerce versions. diff --git a/projects/packages/woocommerce-analytics/changelog/fix-phan-issues_in_old_woo b/projects/packages/woocommerce-analytics/changelog/fix-phan-issues_in_old_woo new file mode 100644 index 0000000000000..a08476d53b87e --- /dev/null +++ b/projects/packages/woocommerce-analytics/changelog/fix-phan-issues_in_old_woo @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Improve compatibility with old WooCommerce versions. From f2d4f781e12518c17cdba10554194b6a3e3695ae Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 19 Nov 2025 10:57:04 -0700 Subject: [PATCH 5/9] Suppress Phan --- .../plugins/wpcomsh/changelog/fix-phan-issues_in_old_woo | 5 +++++ projects/plugins/wpcomsh/woa.php | 1 + 2 files changed, 6 insertions(+) create mode 100644 projects/plugins/wpcomsh/changelog/fix-phan-issues_in_old_woo diff --git a/projects/plugins/wpcomsh/changelog/fix-phan-issues_in_old_woo b/projects/plugins/wpcomsh/changelog/fix-phan-issues_in_old_woo new file mode 100644 index 0000000000000..2251b821a5dad --- /dev/null +++ b/projects/plugins/wpcomsh/changelog/fix-phan-issues_in_old_woo @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: Suppress Phan confusion. + + diff --git a/projects/plugins/wpcomsh/woa.php b/projects/plugins/wpcomsh/woa.php index b705fdd6bb211..98f3329c70910 100644 --- a/projects/plugins/wpcomsh/woa.php +++ b/projects/plugins/wpcomsh/woa.php @@ -429,6 +429,7 @@ function wpcomsh_woa_post_process_store_woocommerce_connection_details( $args, $ WP_CLI::success( 'WooCommerce connection details stored' ); + // @phan-suppress-next-line PhanUndeclaredStaticMethod, UnusedPluginSuppression -- We check if the class and method exist before using them; see https://github.com/phan/phan/issues/1204 if ( class_exists( 'WC_Helper' ) && method_exists( 'WC_Helper', 'refresh_helper_subscriptions' ) ) { WC_Helper::refresh_helper_subscriptions(); From 998eb132edf05372fdcef790c967eb6f5ed513cd Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 19 Nov 2025 11:34:02 -0700 Subject: [PATCH 6/9] Suppress suppression errors --- .../sync/src/modules/class-woocommerce-products.php | 2 +- .../src/class-wc-analytics-tracking.php | 6 +++--- .../woocommerce-analytics/src/class-woo-analytics-trait.php | 4 ++-- projects/plugins/wpcomsh/woa.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/packages/sync/src/modules/class-woocommerce-products.php b/projects/packages/sync/src/modules/class-woocommerce-products.php index 9d5219a20b6db..25ba445381711 100644 --- a/projects/packages/sync/src/modules/class-woocommerce-products.php +++ b/projects/packages/sync/src/modules/class-woocommerce-products.php @@ -445,7 +445,7 @@ private function get_product_posts( $ids, $order = '' ) { * @return array */ private function get_product_cogs_data( $ids, $order = '' ) { - // @phan-suppress-next-line PhanUndeclaredClassReference, PhanUndeclaredClassMethod -- we're checking for the class and method before using them. + // @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredClassReference, PhanUndeclaredClassMethod -- we're checking for the class and method before using them. See also: https://github.com/phan/phan/issues/1204 $is_cogs_enabled = class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && method_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil', 'feature_is_enabled' ) && \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'cost_of_goods_sold' ); if ( ! $is_cogs_enabled ) { diff --git a/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php b/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php index 9f17c5d0ef56a..b70a950aabca5 100644 --- a/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php +++ b/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php @@ -231,7 +231,7 @@ public static function send_batched_pixels() { foreach ( self::$pixel_batch_queue as $pixel ) { // Check if the method exists for backwards compatibility with older WooCommerce versions. if ( method_exists( WC_Tracks_Client::class, 'add_request_timestamp_and_nocache' ) ) { - // @phan-suppress-next-line PhanUndeclaredStaticMethod -- We verify the method exists before using it. + // @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredStaticMethod -- We verify the method exists before using it. See also: https://github.com/phan/phan/issues/1204 $pixels_to_send[] = WC_Tracks_Client::add_request_timestamp_and_nocache( $pixel ); } else { // Fallback for older versions - add timestamp and nocache parameters manually. @@ -388,7 +388,7 @@ public static function get_server_details() { $data = parent::get_server_details(); } elseif ( method_exists( WC_Site_Tracking::class, 'get_server_details' ) ) { // WC < 6.8 - $data = WC_Site_Tracking::get_server_details(); // @phan-suppress-current-line PhanUndeclaredStaticMethod -- method is available in WC < 6.8 + $data = WC_Site_Tracking::get_server_details(); // @phan-suppress-current-line PhanUndeclaredStaticMethod -- method is available in WC < 6.8. See also: https://github.com/phan/phan/issues/1204 } return array_merge( @@ -414,7 +414,7 @@ public static function get_blog_details( $blog_id ) { return parent::get_blog_details( $blog_id ); } elseif ( method_exists( WC_Site_Tracking::class, 'get_blog_details' ) ) { // WC < 6.8 - return WC_Site_Tracking::get_blog_details( $blog_id ); // @phan-suppress-current-line PhanUndeclaredStaticMethod -- method is available in WC < 6.8 + return WC_Site_Tracking::get_blog_details( $blog_id ); // @phan-suppress-current-line PhanUndeclaredStaticMethod -- method is available in WC < 6.8. See also: https://github.com/phan/phan/issues/1204 } return array(); } diff --git a/projects/packages/woocommerce-analytics/src/class-woo-analytics-trait.php b/projects/packages/woocommerce-analytics/src/class-woo-analytics-trait.php index 3f85751567765..648c1ee2fce28 100644 --- a/projects/packages/woocommerce-analytics/src/class-woo-analytics-trait.php +++ b/projects/packages/woocommerce-analytics/src/class-woo-analytics-trait.php @@ -172,7 +172,7 @@ public function find_cart_checkout_content_sources() { $this->cart_checkout_templates_in_use = wp_is_block_theme() && class_exists( '\Automattic\WooCommerce\Blocks\Package' ) - // @phan-suppress-next-line PhanUndeclaredClassMethod -- If the class exists (as of WooCommerce 8.5.0), the method exists. + // @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredClassMethod -- If the class exists (as of WooCommerce 8.5.0), the method exists. See also: https://github.com/phan/phan/issues/1204 && version_compare( \Automattic\WooCommerce\Blocks\Package::get_version(), '10.6.0', '>=' ); // Cart/Checkout *pages* are in use if the templates are not in use. Return their content and do nothing else. @@ -261,7 +261,7 @@ public function find_cart_checkout_content_sources() { public function get_common_properties() { $site_info = array( 'blog_id' => Jetpack_Connection::get_site_id(), - // @phan-suppress-next-line PhanUndeclaredConstantOfClass -- The constant has only existed since WooCommerce 8.4, but we check for its existence. + // @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredConstantOfClass -- The constant has only existed since WooCommerce 8.4, but we check for its existence. See also: https://github.com/phan/phan/issues/1204 'store_id' => defined( '\\WC_Install::STORE_ID_OPTION' ) ? get_option( \WC_Install::STORE_ID_OPTION ) : false, 'ui' => $this->get_user_id(), 'url' => home_url(), diff --git a/projects/plugins/wpcomsh/woa.php b/projects/plugins/wpcomsh/woa.php index 98f3329c70910..93055a2b1b76b 100644 --- a/projects/plugins/wpcomsh/woa.php +++ b/projects/plugins/wpcomsh/woa.php @@ -429,7 +429,7 @@ function wpcomsh_woa_post_process_store_woocommerce_connection_details( $args, $ WP_CLI::success( 'WooCommerce connection details stored' ); - // @phan-suppress-next-line PhanUndeclaredStaticMethod, UnusedPluginSuppression -- We check if the class and method exist before using them; see https://github.com/phan/phan/issues/1204 + // @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredStaticMethod -- We check if the class and method exist before using them; see https://github.com/phan/phan/issues/1204 if ( class_exists( 'WC_Helper' ) && method_exists( 'WC_Helper', 'refresh_helper_subscriptions' ) ) { WC_Helper::refresh_helper_subscriptions(); From de11cf84f51f0c3e66d9f588c3bfab15ab8df4a9 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 19 Nov 2025 11:58:59 -0700 Subject: [PATCH 7/9] Move Phan suppression to correct place --- projects/plugins/wpcomsh/woa.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/wpcomsh/woa.php b/projects/plugins/wpcomsh/woa.php index 93055a2b1b76b..1d850625f0197 100644 --- a/projects/plugins/wpcomsh/woa.php +++ b/projects/plugins/wpcomsh/woa.php @@ -429,8 +429,8 @@ function wpcomsh_woa_post_process_store_woocommerce_connection_details( $args, $ WP_CLI::success( 'WooCommerce connection details stored' ); - // @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredStaticMethod -- We check if the class and method exist before using them; see https://github.com/phan/phan/issues/1204 if ( class_exists( 'WC_Helper' ) && method_exists( 'WC_Helper', 'refresh_helper_subscriptions' ) ) { + // @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredStaticMethod -- We check if the class and method exist before using them; see https://github.com/phan/phan/issues/1204 WC_Helper::refresh_helper_subscriptions(); WP_CLI::success( 'Cleared WooCommerce Helper cache' ); From c4f17d10891ca59537b86f2a2dd7003172249f25 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Thu, 20 Nov 2025 06:40:08 -0700 Subject: [PATCH 8/9] The method was introduced with the class --- .../packages/sync/src/modules/class-woocommerce-products.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/packages/sync/src/modules/class-woocommerce-products.php b/projects/packages/sync/src/modules/class-woocommerce-products.php index 25ba445381711..68d365e65ae52 100644 --- a/projects/packages/sync/src/modules/class-woocommerce-products.php +++ b/projects/packages/sync/src/modules/class-woocommerce-products.php @@ -445,8 +445,8 @@ private function get_product_posts( $ids, $order = '' ) { * @return array */ private function get_product_cogs_data( $ids, $order = '' ) { - // @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredClassReference, PhanUndeclaredClassMethod -- we're checking for the class and method before using them. See also: https://github.com/phan/phan/issues/1204 - $is_cogs_enabled = class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && method_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil', 'feature_is_enabled' ) && \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'cost_of_goods_sold' ); + // @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredClassMethod -- we're checking for the class (around since WooCommerce 7.1) before calling the method (introduced as part of the original class). See also: https://github.com/phan/phan/issues/1204 + $is_cogs_enabled = class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'cost_of_goods_sold' ); if ( ! $is_cogs_enabled ) { return array(); From ddd6f4f9caf38341d0cccc8abc5a20fdfa18a445 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Thu, 20 Nov 2025 07:44:24 -0700 Subject: [PATCH 9/9] Force CI to retry