-
Notifications
You must be signed in to change notification settings - Fork 843
Phan: Address issues discovered while testing against old WooCommerce stubs #46003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
9339cac
4bcb8d6
7524f8b
87f8280
f2d4f78
998eb13
de11cf8
c4f17d1
ddd6f4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: fixed | ||
|
|
||
| Improve compatibility with old WooCommerce versions. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,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-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 ) { | ||
| return array(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: fixed | ||
|
|
||
| Improve compatibility with old WooCommerce versions. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Significance: patch | ||
| Type: fixed | ||
| Comment: Suppress Phan confusion. | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine! I guess we haven't run into any issues here yet, because sync runs on newer stores? or maybe sync has a different plugin requirement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As best I can tell we were lucky and the module itself isn't enabled. It seems to have been added in #44601 and modified in #44601, but both those PRs require a filter to test it, and probably when it was being tested it was done against a newer store.
In other words, this (along with the earlier issues discovered) is precisely what we're hoping to catch with static analysis. 🥳
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally!!