diff --git a/functionMap.php b/functionMap.php index 9fa6e10..d75377e 100644 --- a/functionMap.php +++ b/functionMap.php @@ -52,6 +52,7 @@ 'WP_Http::post' => [$httpReturnType], 'WP_Http::request' => [$httpReturnType], 'wp_list_bookmarks' => ['($args is array{echo: false|0} ? string : void)'], + 'wp_list_categories' => ['($args is array{echo: false|0} ? string|false : false|void)'], 'wp_list_pages' => ['($args is array{echo: false} ? string : void)'], 'WP_List_Table::set_pagination_args' => ['void', 'args' => 'array{total_items?: int, total_pages?: int, per_page?: int}'], 'wp_next_scheduled' => [null, 'args' => $cronArgsType], diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 34c271f..c254ac0 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -36,6 +36,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_error_parameter.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_archives.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_bookmarks.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_categories.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_pages.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_rest_request.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php'); diff --git a/tests/data/wp_list_categories.php b/tests/data/wp_list_categories.php new file mode 100644 index 0000000..1e88675 --- /dev/null +++ b/tests/data/wp_list_categories.php @@ -0,0 +1,31 @@ + true, 'key' => 'value'])); +assertType('false|null', wp_list_categories(['echo' => 1, 'key' => 'value'])); + +// Explicit value of false|0 +assertType('string|false', wp_list_categories(['echo' => false, 'key' => 'value'])); +assertType('string|false', wp_list_categories(['echo' => 0, 'key' => 'value'])); + +// Unknown value +assertType('string|false|null', wp_list_categories(['echo' => (bool)$GET['echo'], 'key' => 'value'])); +assertType('string|false|null', wp_list_categories(['echo' => (int)$GET['echo'], 'key' => 'value'])); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index e4b594e..0adb11a 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -102127,6 +102127,7 @@ function wp_dropdown_categories($args = '') * walker?: Walker, * taxonomy?: string, * } $args + * @phpstan-return ($args is array{echo: false|0} ? string|false : false|void) */ function wp_list_categories($args = '') {