Skip to content

Commit 5b0b623

Browse files
authored
Improve return type for get_post_types (#148)
The result of `get_post_type` is an associative array keyed with the post type slugs.
1 parent b453b46 commit 5b0b623

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

functionMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
'is_wp_error' => ['($thing is \WP_Error ? true : false)', '@phpstan-assert-if-true' => '\WP_Error $thing'],
7878
'current_time' => ["(\$type is 'timestamp'|'U' ? int : string)"],
7979
'mysql2date' => ["(\$format is 'G'|'U' ? int|false : string|false)"],
80-
'get_post_types' => ["(\$output is 'names' ? array<int, string> : array<int, \WP_Post_Type>)"],
80+
'get_post_types' => ["(\$output is 'names' ? array<string, string> : array<string, \WP_Post_Type>)"],
8181
'get_taxonomies' => ["(\$output is 'names' ? array<int, string> : array<int, \WP_Taxonomy>)"],
8282
'get_object_taxonomies' => ["(\$output is 'names' ? array<int, string> : array<string, \WP_Taxonomy>)"],
8383
'get_attachment_taxonomies' => ["(\$output is 'names' ? array<int, string> : array<string, \WP_Taxonomy>)"],

tests/data/get_post_types.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
use function PHPStan\Testing\assertType;
99

1010
// Default output
11-
assertType('array<int, string>', get_post_types([]));
12-
assertType('array<int, string>', get_post_types([], 'names'));
11+
assertType('array<string, string>', get_post_types([]));
12+
assertType('array<string, string>', get_post_types([], 'names'));
1313

1414
// Objects output
15-
assertType('array<int, WP_Post_Type>', get_post_types([], 'objects'));
15+
assertType('array<string, WP_Post_Type>', get_post_types([], 'objects'));
1616

1717
// Unknown string
18-
assertType('array<int, string|WP_Post_Type>', get_post_types([], (string)$_GET['unknown_string']));
18+
assertType('array<string, string|WP_Post_Type>', get_post_types([], (string)$_GET['unknown_string']));
1919

2020
// Unexpected output
21-
assertType('array<int, WP_Post_Type>', get_post_types([], 'Hello'));
21+
assertType('array<string, WP_Post_Type>', get_post_types([], 'Hello'));

wordpress-stubs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125930,7 +125930,7 @@ function get_post_type_object($post_type)
125930125930
* element from the array needs to match; 'and' means all elements
125931125931
* must match; 'not' means no elements may match. Default 'and'.
125932125932
* @return string[]|WP_Post_Type[] An array of post type names or objects.
125933-
* @phpstan-return ($output is 'names' ? array<int, string> : array<int, \WP_Post_Type>)
125933+
* @phpstan-return ($output is 'names' ? array<string, string> : array<string, \WP_Post_Type>)
125934125934
*/
125935125935
function get_post_types($args = array(), $output = 'names', $operator = 'and')
125936125936
{

0 commit comments

Comments
 (0)