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/sync/src/modules/class-woocommerce-products.php b/projects/packages/sync/src/modules/class-woocommerce-products.php index df01192797d28..68d365e65ae52 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; } @@ -444,6 +445,7 @@ 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 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 ) { 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. 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..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,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-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. @@ -387,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( @@ -413,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 26c69b221e82a..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,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-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. @@ -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-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/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..1d850625f0197 100644 --- a/projects/plugins/wpcomsh/woa.php +++ b/projects/plugins/wpcomsh/woa.php @@ -430,6 +430,7 @@ function wpcomsh_woa_post_process_store_woocommerce_connection_details( $args, $ WP_CLI::success( 'WooCommerce connection details stored' ); 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' );