From 665a23d3e6f5c80db64f294cad1a8366800900f0 Mon Sep 17 00:00:00 2001 From: Marian <42134098+IanDelMar@users.noreply.github.com> Date: Wed, 20 Aug 2025 13:04:26 +0200 Subject: [PATCH] Narrow return type for wp_update_category() The function [`wp_update_category()`](https://developer.wordpress.org/reference/functions/wp_update_category/) returns: > The ID number of the new or updated Category on success. Zero or FALSE on failure. --- functionMap.php | 1 + tests/TypeInferenceTest.php | 1 + tests/data/wp_update_category.php | 12 ++++++++++++ wordpress-stubs.php | 1 + 4 files changed, 15 insertions(+) create mode 100644 tests/data/wp_update_category.php diff --git a/functionMap.php b/functionMap.php index 3abf084..b2f2766 100644 --- a/functionMap.php +++ b/functionMap.php @@ -215,6 +215,7 @@ 'wp_unschedule_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args' => $cronArgsType], 'wp_unschedule_hook' => ['($wp_error is false ? int<0, max>|false : int<0, max>|\WP_Error)'], 'wp_unslash' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], + 'wp_update_category' => ['int<0, max>|false'], 'wp_update_comment' => ['($wp_error is false ? 0|1|false : 0|1|\WP_Error)'], 'wp_update_post' => ['($wp_error is false ? int<0, max> : int<1, max>|\WP_Error)'], 'wp_verify_nonce' => ['1|2|false', 'action' => '-1|string'], diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index e5a4d12..4d84fdf 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -112,6 +112,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_translations.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_unique_id.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_update_category.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_widget_factory.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_widget_rss.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_widgets_access_body_class.php'); diff --git a/tests/data/wp_update_category.php b/tests/data/wp_update_category.php new file mode 100644 index 0000000..a2fc542 --- /dev/null +++ b/tests/data/wp_update_category.php @@ -0,0 +1,12 @@ +|false', wp_update_category([])); +assertType('int<0, max>|false', wp_update_category(['cat_ID' => 123])); +assertType('int<0, max>|false', wp_update_category(Faker::array())); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 49c0b3c..0a8c117 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -89581,6 +89581,7 @@ function wp_insert_category($catarr, $wp_error = \false) * * @param array $catarr The 'cat_ID' value is required. All other keys are optional. * @return int|false The ID number of the new or updated Category on success. Zero or FALSE on failure. + * @phpstan-return int<0, max>|false */ function wp_update_category($catarr) {