Skip to content

Commit 5e28d4b

Browse files
authored
functionMap: additions, improvement, corrections (#127)
* Improve return type of get_comment() and get_post() * Add wpdb::get_row() to functions map * Add tests for wp_clear_scheduled_hook() * Add wpdb::get_results() to the functions map * Add get_bookmark() to function map * Add get_category() to function map * Add argument type to get_term() * Use fully qualified name * Add get_category_by_path() to function map * Remove types already added without function map * Add spaces around array assignment operator * Regenerate function map * Add trailing comma to last array item
1 parent e6ec1f4 commit 5e28d4b

File tree

11 files changed

+173
-62
lines changed

11 files changed

+173
-62
lines changed

functionMap.php

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,37 @@
1313
/**
1414
* This array is in the same format as the function map array in PHPStan:
1515
*
16-
* '<function_name>' => ['<return_type>', '<arg_name>'=>'<arg_type>']
16+
* '<function_name>' => ['<return_type>', '<arg_name>' => '<arg_type>']
1717
*
1818
* For classes, or if you don't wish to define the `@phpstan-return` tag:
1919
*
20-
* '<class_name>' => [null, '<arg_name>'=>'<arg_type>']
20+
* '<class_name>' => [null, '<arg_name>' => '<arg_type>']
2121
*
22-
* @link https://github.com/phpstan/phpstan-src/blob/1.5.x/resources/functionMap.php
22+
* @link https://github.com/phpstan/phpstan-src/blob/1.10.x/resources/functionMap.php
2323
*/
2424
return [
25-
'addslashes_gpc' => ['T', '@phpstan-template'=>'T', 'gpc'=>'T'],
26-
'get_objects_in_term' => [null, 'args'=>'array{order?: string}'],
27-
'have_posts' => [null, '@phpstan-impure'=>''],
28-
'rawurlencode_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
29-
'sanitize_category' => ['T', '@phpstan-template'=>'T of array|object', 'category'=>'T'],
30-
'sanitize_post' => ['T', '@phpstan-template'=>'T of array|object', 'post'=>'T'],
31-
'sanitize_term' => ['T', '@phpstan-template'=>'T of array|object', 'term'=>'T'],
32-
'stripslashes_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
33-
'urldecode_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
34-
'urlencode_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
35-
'wp_clear_scheduled_hook' => ['($wp_error is false ? 0|positive-int|false : 0|positive-int|\WP_Error)', 'args'=>$cronArgsType],
25+
'addslashes_gpc' => ['T', '@phpstan-template' => 'T', 'gpc' => 'T'],
26+
'get_objects_in_term' => [null, 'args' => 'array{order?: string}'],
27+
'have_posts' => [null, '@phpstan-impure' => ''],
28+
'rawurlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
29+
'sanitize_category' => ['T', '@phpstan-template' => 'T of array|object', 'category' => 'T'],
30+
'sanitize_post' => ['T', '@phpstan-template' => 'T of array|object', 'post' => 'T'],
31+
'sanitize_term' => ['T', '@phpstan-template' => 'T of array|object', 'term' => 'T'],
32+
'stripslashes_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
33+
'urldecode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
34+
'urlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
35+
'wp_clear_scheduled_hook' => ['(0|positive-int|($wp_error is false ? false : \WP_Error))', 'args'=>$cronArgsType],
3636
'wp_get_schedule' => [null, 'args'=>$cronArgsType],
3737
'wp_get_scheduled_event' => [null, 'args'=>$cronArgsType],
3838
'WP_Http::get' => [$httpReturnType],
3939
'WP_Http::head' => [$httpReturnType],
4040
'WP_Http::post' => [$httpReturnType],
4141
'WP_Http::request' => [$httpReturnType],
42-
'WP_List_Table::display_tablenav' => ['void', 'which'=>'"top"|"bottom"'],
43-
'WP_List_Table::pagination' => ['void', 'which'=>'"top"|"bottom"'],
44-
'WP_List_Table::set_pagination_args' => ['void', 'args'=>'array{total_items?: int, total_pages?: int, per_page?: int}'],
42+
'WP_List_Table::display_tablenav' => ['void', 'which' => '"top"|"bottom"'],
43+
'WP_List_Table::pagination' => ['void', 'which' => '"top"|"bottom"'],
44+
'WP_List_Table::set_pagination_args' => ['void', 'args' => 'array{total_items?: int, total_pages?: int, per_page?: int}'],
4545
'wp_next_scheduled' => [null, 'args'=>$cronArgsType],
46-
'WP_Post_Type::__construct' => ['void', 'args'=>'array<string, mixed>'],
47-
'WP_Query::have_posts' => [null, '@phpstan-impure'=>''],
46+
'WP_Query::have_posts' => [null, '@phpstan-impure' => ''],
4847
'wp_remote_get' => [$httpReturnType],
4948
'wp_remote_head' => [$httpReturnType],
5049
'wp_remote_post' => [$httpReturnType],
@@ -56,26 +55,25 @@
5655
'wp_safe_remote_request' => [$httpReturnType],
5756
'wp_schedule_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args'=>$cronArgsType],
5857
'wp_schedule_single_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args'=>$cronArgsType],
59-
'wp_slash' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
60-
'WP_Taxonomy::__construct' => ['void', 'args'=>'array<string, mixed>'],
58+
'wp_slash' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
6159
'wp_unschedule_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args'=>$cronArgsType],
62-
'wp_unslash' => ['T', '@phpstan-template'=>'T', 'value'=>'T'],
60+
'wp_unslash' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
6361
'wp_widget_rss_form' => ['void', 'args'=>$wpWidgetRssFormArgsType, 'input'=>$wpWidgetRssFormInputType],
64-
'WP_REST_Request' => [null, '@phpstan-template'=>'T of array', '@phpstan-implements'=>'ArrayAccess<key-of<T>, value-of<T>>'],
65-
'WP_REST_Request::offsetExists' => [null, 'offset'=>'@param key-of<T>'],
66-
'WP_REST_Request::offsetGet' => ['T[TOffset]', '@phpstan-template'=>'TOffset of key-of<T>', 'offset'=>'TOffset'],
67-
'WP_REST_Request::offsetSet' => ['void', '@phpstan-template'=>'TOffset of key-of<T>', 'offset'=>'TOffset', 'value'=>'T[TOffset]'],
68-
'WP_REST_Request::offsetUnset' => ['void', '@phpstan-template'=>'TOffset of key-of<T>', 'offset'=>'TOffset'],
62+
'WP_REST_Request' => [null, '@phpstan-template' => 'T of array', '@phpstan-implements' => 'ArrayAccess<key-of<T>, value-of<T>>'],
63+
'WP_REST_Request::offsetExists' => [null, 'offset' => '@param key-of<T>'],
64+
'WP_REST_Request::offsetGet' => ['T[TOffset]', '@phpstan-template' => 'TOffset of key-of<T>', 'offset' => 'TOffset'],
65+
'WP_REST_Request::offsetSet' => ['void', '@phpstan-template' => 'TOffset of key-of<T>', 'offset' => 'TOffset', 'value' => 'T[TOffset]'],
66+
'WP_REST_Request::offsetUnset' => ['void', '@phpstan-template' => 'TOffset of key-of<T>', 'offset' => 'TOffset'],
6967
'WP_Theme' => [null, '@phpstan-type'=>"ThemeKey 'Name'|'Version'|'Status'|'Title'|'Author'|'Author Name'|'Author URI'|'Description'|'Template'|'Stylesheet'|'Template Files'|'Stylesheet Files'|'Template Dir'|'Stylesheet Dir'|'Screenshot'|'Tags'|'Theme Root'|'Theme Root URI'|'Parent Theme'"],
7068
'WP_Theme::get' => ["(\$header is 'Name'|'ThemeURI'|'Description'|'Author'|'AuthorURI'|'Version'|'Template'|'Status'|'Tags'|'TextDomain'|'DomainPath'|'RequiresWP'|'RequiresPHP'|'UpdateURI' ? (\$header is 'Tags' ? string[] : string) : false)"],
7169
'WP_Theme::offsetExists' => ['($offset is ThemeKey ? true : false)'],
7270
'WP_Theme::offsetGet' => ['($offset is ThemeKey ? mixed : null)'],
73-
'WP_Block_List' => [null, '@phpstan-implements'=>'ArrayAccess<int, WP_Block>'],
74-
'WP_Block_List::offsetExists' => [null, 'index'=>'int'],
75-
'WP_Block_List::offsetGet' => ['WP_Block|null', 'index'=>'int'],
76-
'WP_Block_List::offsetSet' => ['void', 'index'=>'int|null'],
77-
'WP_Block_List::offsetUnset' => ['void', 'index'=>'int'],
78-
'is_wp_error' => ['($thing is \WP_Error ? true : false)', '@phpstan-assert-if-true'=>'\WP_Error $thing'],
71+
'WP_Block_List' => [null, '@phpstan-implements' => 'ArrayAccess<int, WP_Block>'],
72+
'WP_Block_List::offsetExists' => [null, 'index' => 'int'],
73+
'WP_Block_List::offsetGet' => ['WP_Block|null', 'index' => 'int'],
74+
'WP_Block_List::offsetSet' => ['void', 'index' => 'int|null'],
75+
'WP_Block_List::offsetUnset' => ['void', 'index' => 'int'],
76+
'is_wp_error' => ['($thing is \WP_Error ? true : false)', '@phpstan-assert-if-true' => '\WP_Error $thing'],
7977
'current_time' => ["(\$type is 'timestamp'|'U' ? int : string)"],
8078
'mysql2date' => ["(\$format is 'G'|'U' ? int|false : string|false)"],
8179
'get_post_types' => ["(\$output is 'names' ? array<int, string> : array<int, \WP_Post_Type>)"],
@@ -84,11 +82,11 @@
8482
'get_attachment_taxonomies' => ["(\$output is 'names' ? array<int, string> : array<string, \WP_Taxonomy>)"],
8583
'get_taxonomies_for_attachments' => ["(\$output is 'names' ? array<int, string> : array<string, \WP_Taxonomy>)"],
8684
'get_post_stati' => ["(\$output is 'names' ? array<string, string> : array<string, \stdClass>)"],
87-
'get_comment' => ["(\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Comment|null))"],
88-
'get_post' => ["(\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Post|null))"],
85+
'get_comment' => ["(\$comment is \WP_Comment ? array<array-key, mixed>|\WP_Comment : array<array-key, mixed>|\WP_Comment|null) & (\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Comment|null))", 'output'=>"'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
86+
'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'" ],
8987
'get_term_by' => ["(\$output is 'ARRAY_A' ? array<string, string|int>|\WP_Error|false : (\$output is 'ARRAY_N' ? list<string|int>|\WP_Error|false : \WP_Term|\WP_Error|false))"],
9088
'get_page_by_path' => ["(\$output is 'ARRAY_A' ? array<string, mixed>|null : (\$output is 'ARRAY_N' ? array<int, mixed>|null : \WP_Post|null))"],
91-
'get_term' => ["(\$output is 'ARRAY_A' ? array<string, string|int>|\WP_Error|null : (\$output is 'ARRAY_N' ? list<string|int>|\WP_Error|null : \WP_Term|\WP_Error|null))"],
89+
'get_term' => ["(\$output is 'ARRAY_A' ? array<string, string|int>|\WP_Error|null : (\$output is 'ARRAY_N' ? list<string|int>|\WP_Error|null : \WP_Term|\WP_Error|null))", 'output'=>"'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
9290
'has_action' => ['($callback is false ? bool : false|int)'],
9391
'has_filter' => ['($callback is false ? bool : false|int)'],
9492
'get_permalink' => ['($post is \WP_Post ? string : string|false)'],
@@ -127,5 +125,10 @@
127125
'WP_Filesystem_Base::dirlist' => [$filesystemDirlistReturnType],
128126
'WP_Filesystem_SSH2::dirlist' => [$filesystemDirlistReturnType],
129127
'WP_Filesystem_ftpsockets::dirlist' => [$filesystemDirlistReturnType],
130-
'wpdb::prepare' => [null, 'query'=>'literal-string'],
128+
'wpdb::prepare' => [null, 'query' => 'literal-string'],
129+
'wpdb::get_row' => ["null|void|(\$output is 'ARRAY_A' ? array<string, mixed> : (\$output is 'ARRAY_N' ? array<int, mixed> : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'", 'y' => '0|positive-int'],
130+
'wpdb::get_results' => ["null|(\$output is 'ARRAY_A' ? array<string, mixed> : (\$output is 'ARRAY_N' ? array<int, mixed> : (\$output is 'OBJECT_K' ? array<string, \stdClass> : \stdClass)))", 'output' => "'OBJECT'|'OBJECT_K'|'ARRAY_A'|'ARRAY_N'"],
131+
'get_bookmark' => ["null|(\$output is 'ARRAY_A' ? array<string, mixed> : (\$output is 'ARRAY_N' ? array<int, mixed> : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
132+
'get_category' => ["(\$category is object ? array<array-key, mixed>|\WP_Term : array<array-key, mixed>|\WP_Term|\WP_Error|null) & (\$output is 'ARRAY_A' ? array<string, mixed>|\WP_Error|null : (\$output is 'ARRAY_N' ? array<int, mixed>|\WP_Error|null : \WP_Term|\WP_Error|null))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
133+
'get_category_by_path' => ["(\$output is 'ARRAY_A' ? array<string, mixed>|\WP_Error|null : (\$output is 'ARRAY_N' ? array<int, mixed>|\WP_Error|null : \WP_Term|\WP_Error|null))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
131134
];

tests/TypeInferenceTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public function dataFileAsserts(): iterable
1212
yield from $this->gatherAssertTypes(__DIR__ . '/data/current_time.php');
1313
yield from $this->gatherAssertTypes(__DIR__ . '/data/echo_parameter.php');
1414
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_attachment_taxonomies.php');
15+
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_bookmark.php');
16+
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_category.php');
17+
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_category_by_path.php');
1518
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_comment.php');
1619
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_object_taxonomies.php');
1720
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_post.php');
@@ -27,8 +30,10 @@ public function dataFileAsserts(): iterable
2730
yield from $this->gatherAssertTypes(__DIR__ . '/data/is_wp_error.php');
2831
yield from $this->gatherAssertTypes(__DIR__ . '/data/mysql2date.php');
2932
yield from $this->gatherAssertTypes(__DIR__ . '/data/term_exists.php');
33+
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_clear_scheduled_hook.php');
3034
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_error_parameter.php');
3135
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php');
36+
yield from $this->gatherAssertTypes(__DIR__ . '/data/wpdb.php');
3237
}
3338

3439
/**

tests/data/get_bookmark.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function get_bookmark;
8+
use function PHPStan\Testing\assertType;
9+
10+
/** @var \stdClass|int $bookmark */
11+
$bookmark;
12+
13+
assertType('stdClass|null', get_bookmark($bookmark));
14+
assertType('stdClass|null', get_bookmark($bookmark, 'OBJECT'));
15+
assertType('array<string, mixed>|null', get_bookmark($bookmark, 'ARRAY_A'));
16+
assertType('array<int, mixed>|null', get_bookmark($bookmark, 'ARRAY_N'));

tests/data/get_category.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function get_category;
8+
use function PHPStan\Testing\assertType;
9+
10+
/** @var object $category */
11+
$category;
12+
13+
assertType('WP_Term', get_category($category));
14+
assertType('WP_Term', get_category($category, 'OBJECT'));
15+
assertType('array<string, mixed>', get_category($category, 'ARRAY_A'));
16+
assertType('array<int, mixed>', get_category($category, 'ARRAY_N'));
17+
18+
/** @var int|object $category */
19+
$category;
20+
21+
assertType('WP_Error|WP_Term|null', get_category($category));
22+
assertType('WP_Error|WP_Term|null', get_category($category, 'OBJECT'));
23+
assertType('array<string, mixed>|WP_Error|null', get_category($category, 'ARRAY_A'));
24+
assertType('array<int, mixed>|WP_Error|null', get_category($category, 'ARRAY_N'));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function get_category_by_path;
8+
use function PHPStan\Testing\assertType;
9+
10+
/** @var bool $bool */
11+
$bool;
12+
13+
assertType('WP_Error|WP_Term|null', get_category_by_path('', $bool, ));
14+
assertType('WP_Error|WP_Term|null', get_category_by_path('', $bool, 'OBJECT'));
15+
assertType('array<string, mixed>|WP_Error|null', get_category_by_path('', $bool, 'ARRAY_A'));
16+
assertType('array<int, mixed>|WP_Error|null', get_category_by_path('', $bool, 'ARRAY_N'));

tests/data/get_comment.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@
77
use function get_comment;
88
use function PHPStan\Testing\assertType;
99

10-
/** @var \WP_Comment|int $comment */
11-
$comment = $comment;
10+
/** @var \WP_Comment|int|string|null $comment */
11+
$comment;
1212

1313
// Default output
1414
assertType('WP_Comment|null', get_comment());
1515
assertType('WP_Comment|null', get_comment($comment));
16-
assertType('WP_Comment|null', get_comment($comment, OBJECT));
16+
assertType('WP_Comment|null', get_comment($comment, 'OBJECT'));
1717

1818
// Associative array output
19-
assertType('array<string, mixed>|null', get_comment($comment, ARRAY_A));
19+
assertType('array<string, mixed>|null', get_comment($comment, 'ARRAY_A'));
2020

2121
// Numeric array output
22-
assertType('array<int, mixed>|null', get_comment($comment, ARRAY_N));
22+
assertType('array<int, mixed>|null', get_comment($comment, 'ARRAY_N'));
2323

24-
// Unknown output
25-
assertType('array<int|string, mixed>|WP_Comment|null', get_comment($comment, (string)$_GET['unknown_string']));
24+
/** @var \WP_Comment $comment */
25+
$comment;
2626

27-
// Unexpected output
28-
assertType('WP_Comment|null', get_comment($comment, 'Hello'));
27+
assertType('WP_Comment', get_comment($comment));
28+
assertType('WP_Comment', get_comment($comment, 'OBJECT'));
29+
assertType('array<string, mixed>', get_comment($comment, 'ARRAY_A'));
30+
assertType('array<int, mixed>', get_comment($comment, 'ARRAY_N'));

tests/data/get_post.php

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

1010
/** @var \WP_Post|int|null $post */
11-
$post = $post;
11+
$post;
1212

1313
// Default output
1414
assertType('WP_Post|null', get_post());
1515
assertType('WP_Post|null', get_post($post));
16-
assertType('WP_Post|null', get_post($post, OBJECT));
16+
assertType('WP_Post|null', get_post($post, 'OBJECT'));
1717

1818
// Associative array output
19-
assertType('array<string, mixed>|null', get_post($post, ARRAY_A));
19+
assertType('array<string, mixed>|null', get_post($post, 'ARRAY_A'));
2020

2121
// Numeric array output
22-
assertType('array<int, mixed>|null', get_post($post, ARRAY_N));
22+
assertType('array<int, mixed>|null', get_post($post, 'ARRAY_N'));
2323

24-
// Unknown output
25-
assertType('array<int|string, mixed>|WP_Post|null', get_post($post, (string)$_GET['unknown_string']));
24+
/** @var \WP_Post $post */
25+
$post;
2626

27-
// Unexpected output
28-
assertType('WP_Post|null', get_post($post, 'Hello'));
27+
assertType('WP_Post', get_post($post));
28+
assertType('WP_Post', get_post($post, 'OBJECT'));
29+
assertType('array<string, mixed>', get_post($post, 'ARRAY_A'));
30+
assertType('array<int, mixed>', get_post($post, 'ARRAY_N'));

tests/data/get_term.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
assertType( 'array<string, int|string>|WP_Error|null', get_term( 2, '', ARRAY_A ) );
1515
assertType( 'array<string, int|string>|WP_Error|null', get_term( 2, 'category', ARRAY_A ) );
1616
assertType( 'array<int, int|string>|WP_Error|null', get_term( 2, '', ARRAY_N ) );
17-
assertType( 'array<int, int|string>|WP_Error|null', get_term( 2, 'category', ARRAY_N ) );
17+
assertType( 'array<int, int|string>|WP_Error|null', get_term( 2, 'category', ARRAY_N ) );
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 wp_clear_scheduled_hook;
8+
use function PHPStan\Testing\assertType;
9+
10+
assertType('int<0, max>|false', wp_clear_scheduled_hook('hook', []));
11+
assertType('int<0, max>|false', wp_clear_scheduled_hook('hook', [], false));
12+
assertType('int<0, max>|WP_Error', wp_clear_scheduled_hook('hook', [], true));

tests/data/wpdb.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use wpdb;
8+
use function PHPStan\Testing\assertType;
9+
10+
// wpdb::get_row()
11+
assertType('stdClass|void|null', wpdb::get_row());
12+
assertType('stdClass|void|null', wpdb::get_row(null, 'OBJECT'));
13+
assertType('array<string, mixed>|void|null', wpdb::get_row(null, 'ARRAY_A'));
14+
assertType('array<int, mixed>|void|null', wpdb::get_row(null, 'ARRAY_N'));
15+
16+
// wpdb::get_results()
17+
assertType('stdClass|null', wpdb::get_results());
18+
assertType('stdClass|null', wpdb::get_results(null, 'OBJECT'));
19+
assertType('array<string, stdClass>|null', wpdb::get_results(null, 'OBJECT_K'));
20+
assertType('array<string, mixed>|null', wpdb::get_results(null, 'ARRAY_A'));
21+
assertType('array<int, mixed>|null', wpdb::get_results(null, 'ARRAY_N'));

0 commit comments

Comments
 (0)