Skip to content

Commit 17066eb

Browse files
authored
Narrow return type of get_post_ancestors (#379)
1 parent 00792be commit 17066eb

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

functionMap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
'get_password_reset_key' => [null, '@phpstan-impure' => ''],
8787
'get_permalink' => ['($post is \WP_Post ? string : string|false)'],
8888
'get_post' => ["(\$post is \WP_Post ? array<array-key, mixed>|\WP_Post : array<array-key, mixed>|\WP_Post|null) & (\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Post|null))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'" ],
89+
'get_post_ancestors' => ['list<int>'],
8990
'get_post_permalink' => ['($post is \WP_Post ? string : string|false)'],
9091
'get_post_stati' => ["(\$output is 'names' ? array<string, string> : array<string, \stdClass>)"],
9192
'get_post_types' => ["(\$output is 'names' ? array<string, string> : array<string, \WP_Post_Type>)"],
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function get_post_ancestors;
8+
use function PHPStan\Testing\assertType;
9+
10+
assertType('list<int>', get_post_ancestors(123));
11+
assertType('list<int>', get_post_ancestors(Faker::int()));
12+
assertType('list<int>', get_post_ancestors(Faker::wpPost()));

wordpress-stubs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131144,6 +131144,7 @@ function get_post($post = \null, $output = \OBJECT, $filter = 'raw')
131144131144
*
131145131145
* @param int|WP_Post $post Post ID or post object.
131146131146
* @return int[] Array of ancestor IDs or empty array if there are none.
131147+
* @phpstan-return list<int>
131147131148
*/
131148131149
function get_post_ancestors($post)
131149131150
{

0 commit comments

Comments
 (0)