Commit b055c8e3b1 for woocommerce
commit b055c8e3b197fc5958d241159581413f1feb1fce
Author: Michael Pretty <prettyboymp@users.noreply.github.com>
Date: Wed Jan 7 13:15:28 2026 -0500
Add PHPStan conditional return type to get_available_variations (#62656)
* Add PHPStan conditional return type to get_available_variations
Add @phpstan-param and @phpstan-return annotations to enable PHPStan
to infer the correct return type based on the $return parameter value.
When called with 'objects', PHPStan now correctly understands the
return type is WC_Product_Variation[] rather than array[].
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Remove resolved PHPStan baseline errors
The conditional return type annotation on get_available_variations()
allows PHPStan to correctly infer WC_Product_Variation[] when called
with 'objects', eliminating 2 false positive errors.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
diff --git a/plugins/woocommerce/changelog/phpstan-variable-product-return-type b/plugins/woocommerce/changelog/phpstan-variable-product-return-type
new file mode 100644
index 0000000000..a405f5eaa9
--- /dev/null
+++ b/plugins/woocommerce/changelog/phpstan-variable-product-return-type
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Add PHPStan conditional return type to WC_Product_Variable::get_available_variations().
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/class-wc-product-variable.php b/plugins/woocommerce/includes/class-wc-product-variable.php
index cd7f99b9a5..4fb472ec12 100644
--- a/plugins/woocommerce/includes/class-wc-product-variable.php
+++ b/plugins/woocommerce/includes/class-wc-product-variable.php
@@ -304,6 +304,8 @@ class WC_Product_Variable extends WC_Product {
* @param string $return Optional. The format to return the results in. Can be 'array' to return an array of variation data or 'objects' for the product objects. Default 'array'.
*
* @return array[]|WC_Product_Variation[]
+ * @phpstan-param 'array'|'objects' $return
+ * @phpstan-return ($return is 'array' ? array[] : WC_Product_Variation[])
*/
public function get_available_variations( $return = 'array' ) {
$variation_ids = $this->get_children();
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 8fd5db9468..5bd8a2c10a 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -58149,18 +58149,6 @@ parameters:
count: 1
path: src/Blocks/BlockTypes/AddToCartWithOptions/Utils.php
- -
- message: '#^Cannot call method get_description\(\) on array\|WC_Product_Variation\.$#'
- identifier: method.nonObject
- count: 1
- path: src/Blocks/BlockTypes/AddToCartWithOptions/VariationDescription.php
-
- -
- message: '#^Cannot call method get_id\(\) on array\|WC_Product_Variation\.$#'
- identifier: method.nonObject
- count: 1
- path: src/Blocks/BlockTypes/AddToCartWithOptions/VariationDescription.php
-
-
message: '#^Parameter \$block of method Automattic\\WooCommerce\\Blocks\\BlockTypes\\AddToCartWithOptions\\VariationDescription\:\:render\(\) has invalid type Automattic\\WooCommerce\\Blocks\\BlockTypes\\AddToCartWithOptions\\WP_Block\.$#'
identifier: class.notFound