diff --git a/functionMap.php b/functionMap.php index 8c8e353..89911d4 100644 --- a/functionMap.php +++ b/functionMap.php @@ -46,6 +46,7 @@ 'wp_die' => ['($args is array{exit: false} ? void : never))'], 'wp_dropdown_languages' => ["(\$args is array{id: null|''} ? void : (\$args is array{name: null|''} ? void : string))"], 'wp_clear_scheduled_hook' => ['(0|positive-int|($wp_error is false ? false : \WP_Error))', 'args' => $cronArgsType], + 'wp_generate_tag_cloud' => ["(\$args is array{format: 'array'} ? array : string)"], 'wp_get_schedule' => [null, 'args' => $cronArgsType], 'wp_get_scheduled_event' => [null, 'args' => $cronArgsType], 'wp_get_archives' => ['($args is array{echo: false|0} ? string : void)'], diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index abe835d..b04f6db 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -38,6 +38,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_die.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_dropdown_languages.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_error_parameter.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_generate_tag_cloud.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_archives.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_is_numeric_array.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_bookmarks.php'); diff --git a/tests/data/wp_generate_tag_cloud.php b/tests/data/wp_generate_tag_cloud.php new file mode 100644 index 0000000..9f52eff --- /dev/null +++ b/tests/data/wp_generate_tag_cloud.php @@ -0,0 +1,28 @@ + $args */ +$tags = $_GET['tags']; + +// Default $args['format] value. +assertType('string', wp_generate_tag_cloud($tags)); +assertType('string', wp_generate_tag_cloud($tags, [])); + +// Requesting array +assertType('array', wp_generate_tag_cloud($tags, ['format' => 'array', 'key' => 'value'])); + +// Requesting string +assertType('string', wp_generate_tag_cloud($tags, ['format' => 'list', 'key' => 'value'])); +assertType('string', wp_generate_tag_cloud($tags, ['format' => 'flat', 'key' => 'value'])); + +// Unexpected $args['format] value +assertType('string', wp_generate_tag_cloud($tags, ['format' => 'unexpected', 'key' => 'value'])); + +// Unknown $args['format] value +assertType('array|string', wp_generate_tag_cloud($tags, ['format' => (string)$_GET['format'], 'key' => 'value'])); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 1496324..3b98d37 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -102255,6 +102255,7 @@ function default_topic_count_scale($count) * topic_count_scale_callback?: callable, * show_count?: bool|int, * } $args + * @phpstan-return ($args is array{format: 'array'} ? array : string) */ function wp_generate_tag_cloud($tags, $args = '') {