Skip to content

Commit d2a203c

Browse files
authored
Merge pull request #195 from IanDelMar/import-extensions
Add conditional return types for several functions
2 parents fc274f7 + 53aac37 commit d2a203c

13 files changed

+409
-13
lines changed

functionMap.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
$httpReturnType = 'array{headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary, body: string, response: array{code: int,message: string}, cookies: array<int, \WP_Http_Cookie>, filename: string|null, http_response: \WP_HTTP_Requests_Response}|\WP_Error';
5+
$httpReturnType = 'array{headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary, body: string, response: array{code: int, message: string}, cookies: array<int, \WP_Http_Cookie>, filename: string|null, http_response: \WP_HTTP_Requests_Response}|\WP_Error';
66

77
if (file_exists(sprintf('%s/source/wordpress/wp-includes/Requests/Cookie/Jar.php', __DIR__))) {
88
$httpReturnType = 'array{headers: \Requests_Utility_CaseInsensitiveDictionary, body: string, response: array{code: int,message: string}, cookies: array<int, \WP_Http_Cookie>, filename: string|null, http_response: \WP_HTTP_Requests_Response}|\WP_Error';
@@ -177,6 +177,15 @@
177177
'WP_Widget::form' => [null, 'instance' => 'T'],
178178
'WP_Widget::update' => [null, 'new_instance' => 'T', 'old_instance' => 'T'],
179179
'WP_Widget::widget' => [null, 'instance' => 'T', 'args' => 'array{name:string,id:string,description:string,class:string,before_widget:string,after_widget:string,before_title:string,after_title:string,before_sidebar:string,after_sidebar:string,show_in_rest:boolean,widget_id:string,widget_name:string}'],
180+
'get_approved_comments' => ["(\$args is array{count: true} ? int : (\$args is array{fields: 'ids'} ? array<int, int> : array<int, \WP_Comment>))"],
181+
'get_posts' => ["(\$args is array{fields: 'id=>parent'|'ids'} ? array<int, int> : array<int, \WP_Post>)"],
182+
'get_sites' => ["(\$args is array{count: true} ? int : (\$args is array{fields: 'ids'} ? array<int, int> : array<int, \WP_Site>))"],
183+
'get_tags' => ["(\$args is array{fields: 'count'} ? numeric-string : (\$args is array{fields: 'names'|'slugs'} ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array<int, string> : (\$args is array{fields: 'id=>parent'} ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'} ? list<int> : array<int, \WP_Term>)))))|\WP_Error"],
184+
'get_terms' => ["(\$args is array{fields: 'count'} ? numeric-string : (\$args is array{fields: 'names'|'slugs'} ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array<int, string> : (\$args is array{fields: 'id=>parent'} ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'} ? list<int> : array<int, \WP_Term>)))))|\WP_Error"],
185+
'wp_get_post_categories' => ["(\$post_id is 0 ? array{} : ((\$args is array{fields: 'names'|'slugs'} ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array<int, string> : (\$args is array{fields: 'id=>parent'} ? array<int, int> : (\$args is array{fields: 'all'|'all_with_object_id'} ? array<int, \WP_Term> : (\$args is array{fields: 'count'} ? numeric-string : list<int>)))))|\WP_Error))"],
186+
'wp_get_post_tags' => ["(\$post_id is 0 ? array{} : ((\$args is array{fields: 'names'|'slugs'} ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array<int, string> : (\$args is array{fields: 'id=>parent'} ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'} ? list<int> : (\$args is array{fields: 'count'} ? numeric-string : array<int, \WP_Term>)))))|\WP_Error))"],
187+
'wp_get_post_terms' => ["(\$post_id is 0 ? array{} : (\$taxonomy is empty ? array{} : ((\$args is array{fields: 'names'|'slugs'} ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array<int, string> : (\$args is array{fields: 'id=>parent'} ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'} ? list<int> : (\$args is array{fields: 'count'} ? numeric-string : array<int, \WP_Term>)))))|\WP_Error)))"],
188+
'wp_get_object_terms' => ["(\$object_ids is empty ? array{} : (\$taxonomies is empty ? array{} : ((\$args is array{fields: 'names'|'slugs'} ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array<int, string> : (\$args is array{fields: 'id=>parent'} ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'} ? list<int> : (\$args is array{fields: 'count'} ? numeric-string : array<int, \WP_Term>)))))|\WP_Error)))"],
180189
'wp_parse_list' => ['($input_list is array ? array<scalar> : list<string>)'],
181190
'wp_parse_str' => [null, '@phpstan-param-out' => 'array<int|string, array|string> $result'],
182191
'size_format' => ["(\$bytes is not numeric ? false : (\$bytes is negative-int|'0' ? false : string))"],

phpcs.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
<rule ref="WordPress.WP.GlobalVariablesOverride">
5151
<exclude-pattern>tests/</exclude-pattern>
5252
</rule>
53+
<rule ref="NeutronStandard.Functions.LongFunction.LongFunction">
54+
<exclude-pattern>tests/TypeInferenceTest.php</exclude-pattern>
55+
</rule>
5356
<rule ref="NeutronStandard.Functions.TypeHint.UnusedReturnType">
5457
<exclude-pattern>tests/TypeInferenceTest.php</exclude-pattern>
5558
</rule>

tests/TypeInferenceTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public function dataFileAsserts(): iterable
1212
yield from $this->gatherAssertTypes(__DIR__ . '/data/_get_list_table.php');
1313
yield from $this->gatherAssertTypes(__DIR__ . '/data/current_time.php');
1414
yield from $this->gatherAssertTypes(__DIR__ . '/data/echo_parameter.php');
15+
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_approved_comments.php');
1516
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_attachment_taxonomies.php');
1617
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_bookmark.php');
1718
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_categories.php');
@@ -22,9 +23,13 @@ public function dataFileAsserts(): iterable
2223
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_post.php');
2324
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_post_stati.php');
2425
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_post_types.php');
26+
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_posts.php');
2527
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_page_by_path.php');
2628
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_permalink.php');
29+
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_sites.php');
30+
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_tags.php');
2731
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_term_by.php');
32+
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_terms.php');
2833
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_taxonomies.php');
2934
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_term.php');
3035
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_taxonomies_for_attachments.php');
@@ -40,6 +45,10 @@ public function dataFileAsserts(): iterable
4045
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_error_parameter.php');
4146
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_generate_tag_cloud.php');
4247
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_archives.php');
48+
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_post_categories.php');
49+
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_post_tags.php');
50+
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_post_terms.php');
51+
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_object_terms.php');
4352
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_is_numeric_array.php');
4453
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_bookmarks.php');
4554
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_categories.php');

tests/data/get_approved_comments.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function get_approved_comments;
8+
use function PHPStan\Testing\assertType;
9+
10+
assertType('array<int, WP_Comment>', get_approved_comments(1));
11+
12+
assertType('int', get_approved_comments(1, ['count' => true]));
13+
14+
assertType('int', get_approved_comments(1, ['count' => true,'fields' => 'ids']));
15+
16+
assertType('array<int, WP_Comment>', get_approved_comments(1, ['count' => false]));
17+
18+
assertType('array<int, int>', get_approved_comments(1, ['fields' => 'ids']));
19+
20+
assertType('array<int, int>', get_approved_comments(1, ['count' => false, 'fields' => 'ids']));

tests/data/get_posts.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function get_posts;
8+
use function PHPStan\Testing\assertType;
9+
10+
assertType('array<int, WP_Post>', get_posts());
11+
assertType('array<int, WP_Post>', get_posts(['key' => 'value']));
12+
assertType('array<int, WP_Post>', get_posts(['fields' => '']));
13+
assertType('array<int, int>', get_posts(['fields' => 'ids']));
14+
assertType('array<int, int>', get_posts(['fields' => 'id=>parent']));
15+
assertType('array<int, WP_Post>', get_posts(['fields' => 'Hello']));
16+
17+
// Nonconstant array
18+
assertType('array<int, int|WP_Post>', get_posts((array)$_GET['array']));
19+
20+
// Unions
21+
$union = $_GET['foo'] ? ['key' => 'value'] : ['some' => 'thing'];
22+
assertType('array<int, WP_Post>', get_posts($union));
23+
24+
$union = $_GET['foo'] ? ['key' => 'value'] : ['fields' => 'ids'];
25+
assertType('array<int, int|WP_Post>', get_posts($union));
26+
27+
$union = $_GET['foo'] ? ['key' => 'value'] : ['fields' => ''];
28+
assertType('array<int, WP_Post>', get_posts($union));
29+
30+
$union = $_GET['foo'] ? ['key' => 'value'] : ['fields' => 'id=>parent'];
31+
assertType('array<int, int|WP_Post>', get_posts($union));
32+
33+
$union = $_GET['foo'] ? ['fields' => ''] : ['fields' => 'ids'];
34+
assertType('array<int, int|WP_Post>', get_posts($union));
35+
36+
$union = $_GET['foo'] ? ['fields' => ''] : ['fields' => 'id=>parent'];
37+
assertType('array<int, int|WP_Post>', get_posts($union));
38+
39+
$union = $_GET['foo'] ? ['fields' => 'ids'] : ['fields' => 'id=>parent'];
40+
assertType('array<int, int>', get_posts($union));
41+
42+
$union = $_GET['foo'] ? (array)$_GET['array'] : ['fields' => ''];
43+
assertType('array<int, int|WP_Post>', get_posts($union));
44+
45+
$union = $_GET['foo'] ? (array)$_GET['array'] : ['fields' => 'ids'];
46+
assertType('array<int, int|WP_Post>', get_posts($union));
47+
48+
$union = $_GET['foo'] ? (array)$_GET['array'] : ['fields' => 'id=>parent'];
49+
assertType('array<int, int|WP_Post>', get_posts($union));
50+
51+
$union = $_GET['foo'] ? (string)$_GET['string'] : '';
52+
assertType('array<int, int|WP_Post>', get_posts(['fields' => $union]));
53+
54+
$union = $_GET['foo'] ? (string)$_GET['string'] : 'ids';
55+
assertType('array<int, int|WP_Post>', get_posts(['fields' => $union]));
56+
57+
$union = $_GET['foo'] ? (string)$_GET['string'] : 'id=>parent';
58+
assertType('array<int, int|WP_Post>', get_posts(['fields' => $union]));
59+
60+
$union = $_GET['foo'] ? (string)$_GET['string'] : 'fields';
61+
assertType('array<int, WP_Post>', get_posts([$union => '']));
62+
63+
$union = $_GET['foo'] ? (string)$_GET['string'] : 'fields';
64+
assertType('array<int, int|WP_Post>', get_posts([$union => 'ids']));
65+
66+
$union = $_GET['foo'] ? (string)$_GET['string'] : 'fields';
67+
assertType('array<int, int|WP_Post>', get_posts([$union => 'id=>parent']));

tests/data/get_sites.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function get_sites;
8+
use function PHPStan\Testing\assertType;
9+
10+
// Default parameter
11+
assertType('array<int, WP_Site>', get_sites());
12+
assertType('array<int, WP_Site>', get_sites([]));
13+
14+
// Non constant array parameter
15+
/** @var array<int|string,mixed> $value */
16+
$value = $_GET['foo'];
17+
assertType('array<int, int|WP_Site>|int', get_sites($value));
18+
19+
// Array parameter with explicit fields value and default count value.
20+
assertType('array<int, int>', get_sites(['fields' => 'ids']));
21+
assertType('array<int, WP_Site>', get_sites(['fields' => '']));
22+
assertType('array<int, WP_Site>', get_sites(['fields' => 'nonEmptyString']));
23+
24+
// Array parameter with count set to true.
25+
assertType('int', get_sites(['count' => true]));
26+
assertType('int', get_sites(['fields' => '', 'count' => true]));
27+
assertType('int', get_sites(['fields' => 'ids', 'count' => true]));
28+
assertType('int', get_sites(['fields' => 'nonEmptyString', 'count' => true]));
29+
30+
// Array parameter with count set to false.
31+
assertType('array<int, WP_Site>', get_sites(['count' => false]));
32+
assertType('array<int, WP_Site>', get_sites(['fields' => '', 'count' => false]));
33+
assertType('array<int, int>', get_sites(['fields' => 'ids', 'count' => false]));
34+
assertType('array<int, WP_Site>', get_sites(['fields' => 'nonEmptyString', 'count' => false]));

tests/data/get_tags.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function get_tags;
8+
use function PHPStan\Testing\assertType;
9+
10+
// Default argument values (fields => all)
11+
assertType('array<int, WP_Term>|WP_Error', get_tags());
12+
assertType('array<int, WP_Term>|WP_Error', get_tags([]));
13+
14+
// Requesting a count
15+
assertType('numeric-string|WP_Error', get_tags(['fields' => 'count']));
16+
assertType('numeric-string|WP_Error', get_tags(['foo' => 'bar','fields' => 'count']));
17+
18+
// Requesting names or slugs
19+
assertType('list<string>|WP_Error', get_tags(['fields' => 'names']));
20+
assertType('list<string>|WP_Error', get_tags(['fields' => 'slugs']));
21+
assertType('array<int, string>|WP_Error', get_tags(['fields' => 'id=>name']));
22+
assertType('array<int, string>|WP_Error', get_tags(['fields' => 'id=>slug']));
23+
24+
// Requesting IDs
25+
assertType('list<int>|WP_Error', get_tags(['fields' => 'ids']));
26+
assertType('list<int>|WP_Error', get_tags(['fields' => 'tt_ids']));
27+
28+
// Requesting parent IDs
29+
assertType('array<int, int>|WP_Error', get_tags(['fields' => 'id=>parent']));
30+
31+
// Requesting objects
32+
assertType('array<int, WP_Term>|WP_Error', get_tags(['fields' => 'all']));
33+
assertType('array<int, WP_Term>|WP_Error', get_tags(['fields' => 'all_with_object_id']));
34+
assertType('array<int, WP_Term>|WP_Error', get_tags(['fields' => 'foo']));
35+
36+
// Unknown fields value
37+
assertType('array<int, int|string|WP_Term>|numeric-string|WP_Error', get_tags(['fields' => (string)$_GET['fields']]));

tests/data/get_terms.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function get_terms;
8+
use function PHPStan\Testing\assertType;
9+
10+
// Default argument values (fields => all)
11+
assertType('array<int, WP_Term>|WP_Error', get_terms());
12+
assertType('array<int, WP_Term>|WP_Error', get_terms([]));
13+
14+
// Requesting a count
15+
assertType('numeric-string|WP_Error', get_terms(['fields' => 'count']));
16+
assertType('numeric-string|WP_Error', get_terms(['foo' => 'bar','fields' => 'count']));
17+
18+
// Requesting names or slugs
19+
assertType('list<string>|WP_Error', get_terms(['fields' => 'names']));
20+
assertType('list<string>|WP_Error', get_terms(['fields' => 'slugs']));
21+
assertType('array<int, string>|WP_Error', get_terms(['fields' => 'id=>name']));
22+
assertType('array<int, string>|WP_Error', get_terms(['fields' => 'id=>slug']));
23+
24+
// Requesting IDs
25+
assertType('list<int>|WP_Error', get_terms(['fields' => 'ids']));
26+
assertType('list<int>|WP_Error', get_terms(['fields' => 'tt_ids']));
27+
28+
// Requesting parent IDs
29+
assertType('array<int, int>|WP_Error', get_terms(['fields' => 'id=>parent']));
30+
31+
// Requesting objects
32+
assertType('array<int, WP_Term>|WP_Error', get_terms(['fields' => 'all']));
33+
assertType('array<int, WP_Term>|WP_Error', get_terms(['fields' => 'all_with_object_id']));
34+
assertType('array<int, WP_Term>|WP_Error', get_terms(['fields' => 'foo']));
35+
36+
// Unknown fields value
37+
assertType('array<int, int|string|WP_Term>|numeric-string|WP_Error', get_terms(['fields' => (string)$_GET['fields']]));

tests/data/wp_get_object_terms.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function wp_get_object_terms;
8+
use function PHPStan\Testing\assertType;
9+
10+
$objectIDs = 123;
11+
$taxonomies = 'category';
12+
13+
// Default argument values (fields => all)
14+
assertType('array<int, WP_Term>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies));
15+
assertType('array<int, WP_Term>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, []));
16+
17+
// Empty $object_ids or $taxonomies
18+
assertType('array{}', wp_get_object_terms(0, $taxonomies, ['fields' => 'count']));
19+
assertType('array{}', wp_get_object_terms([], $taxonomies));
20+
assertType('array{}', wp_get_object_terms($objectIDs, ''));
21+
assertType('array{}', wp_get_object_terms($objectIDs, []));
22+
23+
// Requesting names or slugs
24+
assertType('list<string>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'names']));
25+
assertType('list<string>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'slugs']));
26+
assertType('array<int, string>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'id=>name']));
27+
assertType('array<int, string>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'id=>slug']));
28+
29+
// Requesting IDs
30+
assertType('list<int>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'ids']));
31+
assertType('list<int>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'tt_ids']));
32+
33+
// Requesting parent IDs
34+
assertType('array<int, int>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'id=>parent']));
35+
36+
// Requesting objects
37+
assertType('array<int, WP_Term>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'all']));
38+
assertType('array<int, WP_Term>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'all_with_object_id']));
39+
assertType('array<int, WP_Term>|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'foo']));
40+
41+
// Requesting a count
42+
assertType('numeric-string|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => 'count']));
43+
44+
// Unknown fields value
45+
assertType('array<int, int|string|WP_Term>|numeric-string|WP_Error', wp_get_object_terms($objectIDs, $taxonomies, ['fields' => (string)$_GET['fields']]));

tests/data/wp_get_post_categories.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function wp_get_post_categories;
8+
use function PHPStan\Testing\assertType;
9+
10+
$postID = 123;
11+
12+
// Default argument values (fields => ids)
13+
assertType('list<int>|WP_Error', wp_get_post_categories($postID));
14+
assertType('list<int>|WP_Error', wp_get_post_categories($postID, []));
15+
16+
// Empty $post_id
17+
assertType('array{}', wp_get_post_categories(0));
18+
19+
// Requesting names or slugs
20+
assertType('list<string>|WP_Error', wp_get_post_categories($postID, ['fields' => 'names']));
21+
assertType('list<string>|WP_Error', wp_get_post_categories($postID, ['fields' => 'slugs']));
22+
assertType('array<int, string>|WP_Error', wp_get_post_categories($postID, ['fields' => 'id=>name']));
23+
assertType('array<int, string>|WP_Error', wp_get_post_categories($postID, ['fields' => 'id=>slug']));
24+
25+
// Requesting IDs
26+
assertType('list<int>|WP_Error', wp_get_post_categories($postID, ['fields' => 'ids']));
27+
assertType('list<int>|WP_Error', wp_get_post_categories($postID, ['fields' => 'tt_ids']));
28+
29+
// Requesting parent IDs
30+
assertType('array<int, int>|WP_Error', wp_get_post_categories($postID, ['fields' => 'id=>parent']));
31+
32+
// Requesting objects
33+
assertType('array<int, WP_Term>|WP_Error', wp_get_post_categories($postID, ['fields' => 'all']));
34+
assertType('array<int, WP_Term>|WP_Error', wp_get_post_categories($postID, ['fields' => 'all_with_object_id']));
35+
assertType('list<int>|WP_Error', wp_get_post_categories($postID, ['fields' => 'foo']));
36+
37+
// Requesting a count
38+
assertType('numeric-string|WP_Error', wp_get_post_categories($postID, ['fields' => 'count']));
39+
40+
// Unknown fields value
41+
assertType('array<int, int|string|WP_Term>|numeric-string|WP_Error', wp_get_post_categories($postID, ['fields' => (string)$_GET['fields']]));

0 commit comments

Comments
 (0)