Skip to content

Commit 118b548

Browse files
committed
Add cond. return type for wp_generate_tag_cloud()
1 parent 4582a67 commit 118b548

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

functionMap.php

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
'wp_die' => ['($args is array{exit: false} ? void : never))'],
4747
'wp_dropdown_languages' => ["(\$args is array{id: null|''} ? void : (\$args is array{name: null|''} ? void : string))"],
4848
'wp_clear_scheduled_hook' => ['(0|positive-int|($wp_error is false ? false : \WP_Error))', 'args' => $cronArgsType],
49+
'wp_generate_tag_cloud' => ["(\$args is array{format: 'array'} ? array<int, string> : string)"],
4950
'wp_get_schedule' => [null, 'args' => $cronArgsType],
5051
'wp_get_scheduled_event' => [null, 'args' => $cronArgsType],
5152
'wp_get_archives' => ['($args is array{echo: false|0} ? string : void)'],

tests/TypeInferenceTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function dataFileAsserts(): iterable
3838
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_die.php');
3939
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_dropdown_languages.php');
4040
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_error_parameter.php');
41+
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_generate_tag_cloud.php');
4142
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_archives.php');
4243
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_is_numeric_array.php');
4344
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_bookmarks.php');

tests/data/wp_generate_tag_cloud.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function wp_generate_tag_cloud;
8+
use function PHPStan\Testing\assertType;
9+
10+
/** @var array<\WP_Term> $args */
11+
$tags = $_GET['tags'];
12+
13+
// Default $args['format] value.
14+
assertType('string', wp_generate_tag_cloud($tags));
15+
assertType('string', wp_generate_tag_cloud($tags, []));
16+
17+
// Requesting array
18+
assertType('array<int, string>', wp_generate_tag_cloud($tags, ['format' => 'array', 'key' => 'value']));
19+
20+
// Requesting string
21+
assertType('string', wp_generate_tag_cloud($tags, ['format' => 'list', 'key' => 'value']));
22+
assertType('string', wp_generate_tag_cloud($tags, ['format' => 'flat', 'key' => 'value']));
23+
24+
// Unexpected $args['format] value
25+
assertType('string', wp_generate_tag_cloud($tags, ['format' => 'unexpected', 'key' => 'value']));
26+
27+
// Unknown $args['format] value
28+
assertType('array<int, string>|string', wp_generate_tag_cloud($tags, ['format' => (string)$_GET['format'], 'key' => 'value']));

wordpress-stubs.php

+1
Original file line numberDiff line numberDiff line change
@@ -102255,6 +102255,7 @@ function default_topic_count_scale($count)
102255102255
* topic_count_scale_callback?: callable,
102256102256
* show_count?: bool|int,
102257102257
* } $args
102258+
* @phpstan-return ($args is array{format: 'array'} ? array<int, string> : string)
102258102259
*/
102259102260
function wp_generate_tag_cloud($tags, $args = '')
102260102261
{

0 commit comments

Comments
 (0)