diff --git a/functionMap.php b/functionMap.php index 89911d4..7b1082e 100644 --- a/functionMap.php +++ b/functionMap.php @@ -73,6 +73,7 @@ 'wp_schedule_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args' => $cronArgsType], 'wp_schedule_single_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args' => $cronArgsType], 'wp_slash' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], + 'wp_tag_cloud' => ["(\$args is array{format: 'array'} ? array|void : (\$args is array{echo: false|0} ? string|void : void))"], 'wp_unschedule_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args' => $cronArgsType], 'wp_unslash' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], 'wp_widget_rss_form' => ['void', 'args' => $wpWidgetRssFormArgsType, 'inputs' => $wpWidgetRssFormInputsType], diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index b04f6db..9a9ad05 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -46,6 +46,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_pages.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_parse_list.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_rest_request.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_tag_cloud.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wpdb.php'); } diff --git a/tests/data/wp_tag_cloud.php b/tests/data/wp_tag_cloud.php new file mode 100644 index 0000000..07a17d3 --- /dev/null +++ b/tests/data/wp_tag_cloud.php @@ -0,0 +1,48 @@ + true])); +assertType('null', wp_tag_cloud(['format' => 'flat', 'echo' => true])); +assertType('null', wp_tag_cloud(['format' => 'list', 'echo' => true])); +assertType('null', wp_tag_cloud(['format' => 'unexpected', 'echo' => true])); + +// Echo true, but format (maybe) array +assertType('array|null', wp_tag_cloud(['format' => 'array', 'echo' => true])); +assertType('array|null', wp_tag_cloud(['format' => (string)$_GET['format'], 'echo' => true])); + +// Echo false +assertType('string|null', wp_tag_cloud(['echo' => false])); +assertType('string|null', wp_tag_cloud(['format' => 'flat', 'echo' => false])); +assertType('string|null', wp_tag_cloud(['format' => 'list', 'echo' => false])); +assertType('array|null', wp_tag_cloud(['format' => 'array', 'echo' => false])); +assertType('string|null', wp_tag_cloud(['format' => 'unexpected', 'echo' => false])); +assertType('array|string|null', wp_tag_cloud(['format' => (string)$_GET['format'], 'echo' => false])); + +// Echo unknown +/** @var bool|0|1 $echo */ +$boolZeroOne = $_GET['echo']; + +assertType('string|null', wp_tag_cloud(['echo' => $boolZeroOne])); +assertType('string|null', wp_tag_cloud(['format' => 'flat', 'echo' => $boolZeroOne])); +assertType('string|null', wp_tag_cloud(['format' => 'list', 'echo' => $boolZeroOne])); +assertType('array|null', wp_tag_cloud(['format' => 'array', 'echo' => $boolZeroOne])); +assertType('string|null', wp_tag_cloud(['format' => 'unexpected', 'echo' => $boolZeroOne])); +assertType('array|string|null', wp_tag_cloud(['format' => (string)$_GET['format'], 'echo' => $boolZeroOne])); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 3b98d37..b4e8cfc 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -102180,6 +102180,7 @@ function wp_list_categories($args = '') * topic_count_scale_callback?: callable, * show_count?: bool|int, * } $args + * @phpstan-return ($args is array{format: 'array'} ? array|void : ($args is array{echo: false|0} ? string|void : void)) */ function wp_tag_cloud($args = '') {