From 5e28d4bc664dd2c613ac45297eedd1c1cce0f5e0 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Thu, 2 Nov 2023 21:58:16 +0100 Subject: [PATCH] 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 --- functionMap.php | 77 +++++++++++++------------- tests/TypeInferenceTest.php | 5 ++ tests/data/get_bookmark.php | 16 ++++++ tests/data/get_category.php | 24 ++++++++ tests/data/get_category_by_path.php | 16 ++++++ tests/data/get_comment.php | 20 ++++--- tests/data/get_post.php | 18 +++--- tests/data/get_term.php | 2 +- tests/data/wp_clear_scheduled_hook.php | 12 ++++ tests/data/wpdb.php | 21 +++++++ wordpress-stubs.php | 24 +++++--- 11 files changed, 173 insertions(+), 62 deletions(-) create mode 100644 tests/data/get_bookmark.php create mode 100644 tests/data/get_category.php create mode 100644 tests/data/get_category_by_path.php create mode 100644 tests/data/wp_clear_scheduled_hook.php create mode 100644 tests/data/wpdb.php diff --git a/functionMap.php b/functionMap.php index b73efa5..3d7c85e 100644 --- a/functionMap.php +++ b/functionMap.php @@ -13,38 +13,37 @@ /** * This array is in the same format as the function map array in PHPStan: * - * '' => ['', ''=>''] + * '' => ['', '' => ''] * * For classes, or if you don't wish to define the `@phpstan-return` tag: * - * '' => [null, ''=>''] + * '' => [null, '' => ''] * - * @link https://github.com/phpstan/phpstan-src/blob/1.5.x/resources/functionMap.php + * @link https://github.com/phpstan/phpstan-src/blob/1.10.x/resources/functionMap.php */ return [ - 'addslashes_gpc' => ['T', '@phpstan-template'=>'T', 'gpc'=>'T'], - 'get_objects_in_term' => [null, 'args'=>'array{order?: string}'], - 'have_posts' => [null, '@phpstan-impure'=>''], - 'rawurlencode_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'], - 'sanitize_category' => ['T', '@phpstan-template'=>'T of array|object', 'category'=>'T'], - 'sanitize_post' => ['T', '@phpstan-template'=>'T of array|object', 'post'=>'T'], - 'sanitize_term' => ['T', '@phpstan-template'=>'T of array|object', 'term'=>'T'], - 'stripslashes_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'], - 'urldecode_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'], - 'urlencode_deep' => ['T', '@phpstan-template'=>'T', 'value'=>'T'], - 'wp_clear_scheduled_hook' => ['($wp_error is false ? 0|positive-int|false : 0|positive-int|\WP_Error)', 'args'=>$cronArgsType], + 'addslashes_gpc' => ['T', '@phpstan-template' => 'T', 'gpc' => 'T'], + 'get_objects_in_term' => [null, 'args' => 'array{order?: string}'], + 'have_posts' => [null, '@phpstan-impure' => ''], + 'rawurlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], + 'sanitize_category' => ['T', '@phpstan-template' => 'T of array|object', 'category' => 'T'], + 'sanitize_post' => ['T', '@phpstan-template' => 'T of array|object', 'post' => 'T'], + 'sanitize_term' => ['T', '@phpstan-template' => 'T of array|object', 'term' => 'T'], + 'stripslashes_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], + 'urldecode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], + 'urlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], + 'wp_clear_scheduled_hook' => ['(0|positive-int|($wp_error is false ? false : \WP_Error))', 'args'=>$cronArgsType], 'wp_get_schedule' => [null, 'args'=>$cronArgsType], 'wp_get_scheduled_event' => [null, 'args'=>$cronArgsType], 'WP_Http::get' => [$httpReturnType], 'WP_Http::head' => [$httpReturnType], 'WP_Http::post' => [$httpReturnType], 'WP_Http::request' => [$httpReturnType], - 'WP_List_Table::display_tablenav' => ['void', 'which'=>'"top"|"bottom"'], - 'WP_List_Table::pagination' => ['void', 'which'=>'"top"|"bottom"'], - 'WP_List_Table::set_pagination_args' => ['void', 'args'=>'array{total_items?: int, total_pages?: int, per_page?: int}'], + 'WP_List_Table::display_tablenav' => ['void', 'which' => '"top"|"bottom"'], + 'WP_List_Table::pagination' => ['void', 'which' => '"top"|"bottom"'], + 'WP_List_Table::set_pagination_args' => ['void', 'args' => 'array{total_items?: int, total_pages?: int, per_page?: int}'], 'wp_next_scheduled' => [null, 'args'=>$cronArgsType], - 'WP_Post_Type::__construct' => ['void', 'args'=>'array'], - 'WP_Query::have_posts' => [null, '@phpstan-impure'=>''], + 'WP_Query::have_posts' => [null, '@phpstan-impure' => ''], 'wp_remote_get' => [$httpReturnType], 'wp_remote_head' => [$httpReturnType], 'wp_remote_post' => [$httpReturnType], @@ -56,26 +55,25 @@ 'wp_safe_remote_request' => [$httpReturnType], 'wp_schedule_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args'=>$cronArgsType], 'wp_schedule_single_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args'=>$cronArgsType], - 'wp_slash' => ['T', '@phpstan-template'=>'T', 'value'=>'T'], - 'WP_Taxonomy::__construct' => ['void', 'args'=>'array'], + 'wp_slash' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], 'wp_unschedule_event' => ['($wp_error is false ? bool : true|\WP_Error)', 'args'=>$cronArgsType], - 'wp_unslash' => ['T', '@phpstan-template'=>'T', 'value'=>'T'], + 'wp_unslash' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], 'wp_widget_rss_form' => ['void', 'args'=>$wpWidgetRssFormArgsType, 'input'=>$wpWidgetRssFormInputType], - 'WP_REST_Request' => [null, '@phpstan-template'=>'T of array', '@phpstan-implements'=>'ArrayAccess, value-of>'], - 'WP_REST_Request::offsetExists' => [null, 'offset'=>'@param key-of'], - 'WP_REST_Request::offsetGet' => ['T[TOffset]', '@phpstan-template'=>'TOffset of key-of', 'offset'=>'TOffset'], - 'WP_REST_Request::offsetSet' => ['void', '@phpstan-template'=>'TOffset of key-of', 'offset'=>'TOffset', 'value'=>'T[TOffset]'], - 'WP_REST_Request::offsetUnset' => ['void', '@phpstan-template'=>'TOffset of key-of', 'offset'=>'TOffset'], + 'WP_REST_Request' => [null, '@phpstan-template' => 'T of array', '@phpstan-implements' => 'ArrayAccess, value-of>'], + 'WP_REST_Request::offsetExists' => [null, 'offset' => '@param key-of'], + 'WP_REST_Request::offsetGet' => ['T[TOffset]', '@phpstan-template' => 'TOffset of key-of', 'offset' => 'TOffset'], + 'WP_REST_Request::offsetSet' => ['void', '@phpstan-template' => 'TOffset of key-of', 'offset' => 'TOffset', 'value' => 'T[TOffset]'], + 'WP_REST_Request::offsetUnset' => ['void', '@phpstan-template' => 'TOffset of key-of', 'offset' => 'TOffset'], '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'"], '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)"], 'WP_Theme::offsetExists' => ['($offset is ThemeKey ? true : false)'], 'WP_Theme::offsetGet' => ['($offset is ThemeKey ? mixed : null)'], - 'WP_Block_List' => [null, '@phpstan-implements'=>'ArrayAccess'], - 'WP_Block_List::offsetExists' => [null, 'index'=>'int'], - 'WP_Block_List::offsetGet' => ['WP_Block|null', 'index'=>'int'], - 'WP_Block_List::offsetSet' => ['void', 'index'=>'int|null'], - 'WP_Block_List::offsetUnset' => ['void', 'index'=>'int'], - 'is_wp_error' => ['($thing is \WP_Error ? true : false)', '@phpstan-assert-if-true'=>'\WP_Error $thing'], + 'WP_Block_List' => [null, '@phpstan-implements' => 'ArrayAccess'], + 'WP_Block_List::offsetExists' => [null, 'index' => 'int'], + 'WP_Block_List::offsetGet' => ['WP_Block|null', 'index' => 'int'], + 'WP_Block_List::offsetSet' => ['void', 'index' => 'int|null'], + 'WP_Block_List::offsetUnset' => ['void', 'index' => 'int'], + 'is_wp_error' => ['($thing is \WP_Error ? true : false)', '@phpstan-assert-if-true' => '\WP_Error $thing'], 'current_time' => ["(\$type is 'timestamp'|'U' ? int : string)"], 'mysql2date' => ["(\$format is 'G'|'U' ? int|false : string|false)"], 'get_post_types' => ["(\$output is 'names' ? array : array)"], @@ -84,11 +82,11 @@ 'get_attachment_taxonomies' => ["(\$output is 'names' ? array : array)"], 'get_taxonomies_for_attachments' => ["(\$output is 'names' ? array : array)"], 'get_post_stati' => ["(\$output is 'names' ? array : array)"], - 'get_comment' => ["(\$output is 'ARRAY_A' ? array|null : (\$output is 'ARRAY_N' ? array|null : \WP_Comment|null))"], - 'get_post' => ["(\$output is 'ARRAY_A' ? array|null : (\$output is 'ARRAY_N' ? array|null : \WP_Post|null))"], + 'get_comment' => ["(\$comment is \WP_Comment ? array|\WP_Comment : array|\WP_Comment|null) & (\$output is 'ARRAY_A' ? array|null : (\$output is 'ARRAY_N' ? array|null : \WP_Comment|null))", 'output'=>"'OBJECT'|'ARRAY_A'|'ARRAY_N'"], + 'get_post' => ["(\$post is \WP_Post ? array|\WP_Post : array|\WP_Post|null) & (\$output is 'ARRAY_A' ? array|null : (\$output is 'ARRAY_N' ? array|null : \WP_Post|null))", 'output'=>"'OBJECT'|'ARRAY_A'|'ARRAY_N'" ], 'get_term_by' => ["(\$output is 'ARRAY_A' ? array|\WP_Error|false : (\$output is 'ARRAY_N' ? list|\WP_Error|false : \WP_Term|\WP_Error|false))"], 'get_page_by_path' => ["(\$output is 'ARRAY_A' ? array|null : (\$output is 'ARRAY_N' ? array|null : \WP_Post|null))"], - 'get_term' => ["(\$output is 'ARRAY_A' ? array|\WP_Error|null : (\$output is 'ARRAY_N' ? list|\WP_Error|null : \WP_Term|\WP_Error|null))"], + 'get_term' => ["(\$output is 'ARRAY_A' ? array|\WP_Error|null : (\$output is 'ARRAY_N' ? list|\WP_Error|null : \WP_Term|\WP_Error|null))", 'output'=>"'OBJECT'|'ARRAY_A'|'ARRAY_N'"], 'has_action' => ['($callback is false ? bool : false|int)'], 'has_filter' => ['($callback is false ? bool : false|int)'], 'get_permalink' => ['($post is \WP_Post ? string : string|false)'], @@ -127,5 +125,10 @@ 'WP_Filesystem_Base::dirlist' => [$filesystemDirlistReturnType], 'WP_Filesystem_SSH2::dirlist' => [$filesystemDirlistReturnType], 'WP_Filesystem_ftpsockets::dirlist' => [$filesystemDirlistReturnType], - 'wpdb::prepare' => [null, 'query'=>'literal-string'], + 'wpdb::prepare' => [null, 'query' => 'literal-string'], + 'wpdb::get_row' => ["null|void|(\$output is 'ARRAY_A' ? array : (\$output is 'ARRAY_N' ? array : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'", 'y' => '0|positive-int'], + 'wpdb::get_results' => ["null|(\$output is 'ARRAY_A' ? array : (\$output is 'ARRAY_N' ? array : (\$output is 'OBJECT_K' ? array : \stdClass)))", 'output' => "'OBJECT'|'OBJECT_K'|'ARRAY_A'|'ARRAY_N'"], + 'get_bookmark' => ["null|(\$output is 'ARRAY_A' ? array : (\$output is 'ARRAY_N' ? array : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"], + 'get_category' => ["(\$category is object ? array|\WP_Term : array|\WP_Term|\WP_Error|null) & (\$output is 'ARRAY_A' ? array|\WP_Error|null : (\$output is 'ARRAY_N' ? array|\WP_Error|null : \WP_Term|\WP_Error|null))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"], + 'get_category_by_path' => ["(\$output is 'ARRAY_A' ? array|\WP_Error|null : (\$output is 'ARRAY_N' ? array|\WP_Error|null : \WP_Term|\WP_Error|null))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"], ]; diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 010717e..0d6c404 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -12,6 +12,9 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/current_time.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/echo_parameter.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_attachment_taxonomies.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/get_bookmark.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/get_category.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/get_category_by_path.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_comment.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_object_taxonomies.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/get_post.php'); @@ -27,8 +30,10 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/is_wp_error.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/mysql2date.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/term_exists.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_clear_scheduled_hook.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_error_parameter.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/wpdb.php'); } /** diff --git a/tests/data/get_bookmark.php b/tests/data/get_bookmark.php new file mode 100644 index 0000000..6f8e327 --- /dev/null +++ b/tests/data/get_bookmark.php @@ -0,0 +1,16 @@ +|null', get_bookmark($bookmark, 'ARRAY_A')); +assertType('array|null', get_bookmark($bookmark, 'ARRAY_N')); diff --git a/tests/data/get_category.php b/tests/data/get_category.php new file mode 100644 index 0000000..85862da --- /dev/null +++ b/tests/data/get_category.php @@ -0,0 +1,24 @@ +', get_category($category, 'ARRAY_A')); +assertType('array', get_category($category, 'ARRAY_N')); + +/** @var int|object $category */ +$category; + +assertType('WP_Error|WP_Term|null', get_category($category)); +assertType('WP_Error|WP_Term|null', get_category($category, 'OBJECT')); +assertType('array|WP_Error|null', get_category($category, 'ARRAY_A')); +assertType('array|WP_Error|null', get_category($category, 'ARRAY_N')); diff --git a/tests/data/get_category_by_path.php b/tests/data/get_category_by_path.php new file mode 100644 index 0000000..9b07cb7 --- /dev/null +++ b/tests/data/get_category_by_path.php @@ -0,0 +1,16 @@ +|WP_Error|null', get_category_by_path('', $bool, 'ARRAY_A')); +assertType('array|WP_Error|null', get_category_by_path('', $bool, 'ARRAY_N')); diff --git a/tests/data/get_comment.php b/tests/data/get_comment.php index e38228b..f0bcc77 100644 --- a/tests/data/get_comment.php +++ b/tests/data/get_comment.php @@ -7,22 +7,24 @@ use function get_comment; use function PHPStan\Testing\assertType; -/** @var \WP_Comment|int $comment */ -$comment = $comment; +/** @var \WP_Comment|int|string|null $comment */ +$comment; // Default output assertType('WP_Comment|null', get_comment()); assertType('WP_Comment|null', get_comment($comment)); -assertType('WP_Comment|null', get_comment($comment, OBJECT)); +assertType('WP_Comment|null', get_comment($comment, 'OBJECT')); // Associative array output -assertType('array|null', get_comment($comment, ARRAY_A)); +assertType('array|null', get_comment($comment, 'ARRAY_A')); // Numeric array output -assertType('array|null', get_comment($comment, ARRAY_N)); +assertType('array|null', get_comment($comment, 'ARRAY_N')); -// Unknown output -assertType('array|WP_Comment|null', get_comment($comment, (string)$_GET['unknown_string'])); +/** @var \WP_Comment $comment */ +$comment; -// Unexpected output -assertType('WP_Comment|null', get_comment($comment, 'Hello')); +assertType('WP_Comment', get_comment($comment)); +assertType('WP_Comment', get_comment($comment, 'OBJECT')); +assertType('array', get_comment($comment, 'ARRAY_A')); +assertType('array', get_comment($comment, 'ARRAY_N')); diff --git a/tests/data/get_post.php b/tests/data/get_post.php index 5766f85..8061772 100644 --- a/tests/data/get_post.php +++ b/tests/data/get_post.php @@ -8,21 +8,23 @@ use function PHPStan\Testing\assertType; /** @var \WP_Post|int|null $post */ -$post = $post; +$post; // Default output assertType('WP_Post|null', get_post()); assertType('WP_Post|null', get_post($post)); -assertType('WP_Post|null', get_post($post, OBJECT)); +assertType('WP_Post|null', get_post($post, 'OBJECT')); // Associative array output -assertType('array|null', get_post($post, ARRAY_A)); +assertType('array|null', get_post($post, 'ARRAY_A')); // Numeric array output -assertType('array|null', get_post($post, ARRAY_N)); +assertType('array|null', get_post($post, 'ARRAY_N')); -// Unknown output -assertType('array|WP_Post|null', get_post($post, (string)$_GET['unknown_string'])); +/** @var \WP_Post $post */ +$post; -// Unexpected output -assertType('WP_Post|null', get_post($post, 'Hello')); +assertType('WP_Post', get_post($post)); +assertType('WP_Post', get_post($post, 'OBJECT')); +assertType('array', get_post($post, 'ARRAY_A')); +assertType('array', get_post($post, 'ARRAY_N')); diff --git a/tests/data/get_term.php b/tests/data/get_term.php index fcb209b..8541267 100644 --- a/tests/data/get_term.php +++ b/tests/data/get_term.php @@ -14,4 +14,4 @@ assertType( 'array|WP_Error|null', get_term( 2, '', ARRAY_A ) ); assertType( 'array|WP_Error|null', get_term( 2, 'category', ARRAY_A ) ); assertType( 'array|WP_Error|null', get_term( 2, '', ARRAY_N ) ); -assertType( 'array|WP_Error|null', get_term( 2, 'category', ARRAY_N ) ); \ No newline at end of file +assertType( 'array|WP_Error|null', get_term( 2, 'category', ARRAY_N ) ); diff --git a/tests/data/wp_clear_scheduled_hook.php b/tests/data/wp_clear_scheduled_hook.php new file mode 100644 index 0000000..17a7a77 --- /dev/null +++ b/tests/data/wp_clear_scheduled_hook.php @@ -0,0 +1,12 @@ +|false', wp_clear_scheduled_hook('hook', [])); +assertType('int<0, max>|false', wp_clear_scheduled_hook('hook', [], false)); +assertType('int<0, max>|WP_Error', wp_clear_scheduled_hook('hook', [], true)); diff --git a/tests/data/wpdb.php b/tests/data/wpdb.php new file mode 100644 index 0000000..60a697f --- /dev/null +++ b/tests/data/wpdb.php @@ -0,0 +1,21 @@ +|void|null', wpdb::get_row(null, 'ARRAY_A')); +assertType('array|void|null', wpdb::get_row(null, 'ARRAY_N')); + +// wpdb::get_results() +assertType('stdClass|null', wpdb::get_results()); +assertType('stdClass|null', wpdb::get_results(null, 'OBJECT')); +assertType('array|null', wpdb::get_results(null, 'OBJECT_K')); +assertType('array|null', wpdb::get_results(null, 'ARRAY_A')); +assertType('array|null', wpdb::get_results(null, 'ARRAY_N')); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 7dba24e..f2b0e2c 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -44535,8 +44535,6 @@ final class WP_Post_Type * _builtin?: bool, * _edit_link?: string, * } $args See register_post_type() - * @phpstan-param array $args - * @phpstan-return void */ public function __construct($post_type, $args = array()) { @@ -50056,8 +50054,6 @@ final class WP_Taxonomy * args?: array, * _builtin?: bool, * } $args See register_taxonomy() - * @phpstan-param array $args - * @phpstan-return void */ public function __construct($taxonomy, $object_type, $args = array()) { @@ -58707,6 +58703,9 @@ public function get_var($query = \null, $x = 0, $y = 0) * respectively. Default OBJECT. * @param int $y Optional. Row to return. Indexed from 0. Default 0. * @return array|object|null|void Database query result in format specified by $output or null on failure. + * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output + * @phpstan-param 0|positive-int $y + * @phpstan-return null|void|($output is 'ARRAY_A' ? array : ($output is 'ARRAY_N' ? array : \stdClass)) */ public function get_row($query = \null, $output = \OBJECT, $y = 0) { @@ -58744,6 +58743,8 @@ public function get_col($query = \null, $x = 0) * of each row's first column's value. Duplicate keys are discarded. * Default OBJECT. * @return array|object|null Database query results. + * @phpstan-param 'OBJECT'|'OBJECT_K'|'ARRAY_A'|'ARRAY_N' $output + * @phpstan-return null|($output is 'ARRAY_A' ? array : ($output is 'ARRAY_N' ? array : ($output is 'OBJECT_K' ? array : \stdClass))) */ public function get_results($query = \null, $output = \OBJECT) { @@ -92403,6 +92404,8 @@ function wp_list_bookmarks($args = '') * respectively. Default OBJECT. * @param string $filter Optional. How to sanitize bookmark fields. Default 'raw'. * @return array|object|null Type returned depends on $output value. + * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output + * @phpstan-return null|($output is 'ARRAY_A' ? array : ($output is 'ARRAY_N' ? array : \stdClass)) */ function get_bookmark($bookmark, $output = \OBJECT, $filter = 'raw') { @@ -94032,6 +94035,8 @@ function get_categories($args = '') * @param string $filter Optional. How to sanitize category fields. Default 'raw'. * @return object|array|WP_Error|null Category data in type defined by $output parameter. * WP_Error if $category is empty, null if it does not exist. + * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output + * @phpstan-return ($category is object ? array|\WP_Term : array|\WP_Term|\WP_Error|null) & ($output is 'ARRAY_A' ? array|\WP_Error|null : ($output is 'ARRAY_N' ? array|\WP_Error|null : \WP_Term|\WP_Error|null)) */ function get_category($category, $output = \OBJECT, $filter = 'raw') { @@ -94056,6 +94061,8 @@ function get_category($category, $output = \OBJECT, $filter = 'raw') * correspond to a WP_Term object, an associative array, or a numeric array, * respectively. Default OBJECT. * @return WP_Term|array|WP_Error|null Type is based on $output value. + * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output + * @phpstan-return ($output is 'ARRAY_A' ? array|\WP_Error|null : ($output is 'ARRAY_N' ? array|\WP_Error|null : \WP_Term|\WP_Error|null)) */ function get_category_by_path($category_path, $full_match = \true, $output = \OBJECT) { @@ -95462,7 +95469,8 @@ function get_approved_comments($post_id, $args = array()) * correspond to a WP_Comment object, an associative array, or a numeric array, * respectively. Default OBJECT. * @return WP_Comment|array|null Depends on $output value. - * @phpstan-return ($output is 'ARRAY_A' ? array|null : ($output is 'ARRAY_N' ? array|null : \WP_Comment|null)) + * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output + * @phpstan-return ($comment is \WP_Comment ? array|\WP_Comment : array|\WP_Comment|null) & ($output is 'ARRAY_A' ? array|null : ($output is 'ARRAY_N' ? array|null : \WP_Comment|null)) */ function get_comment($comment = \null, $output = \OBJECT) { @@ -96836,7 +96844,7 @@ function wp_unschedule_event($timestamp, $hook, $args = array(), $wp_error = \fa * events were registered with the hook and arguments combination), false or WP_Error * if unscheduling one or more events fail. * @phpstan-param list $args - * @phpstan-return ($wp_error is false ? 0|positive-int|false : 0|positive-int|\WP_Error) + * @phpstan-return (0|positive-int|($wp_error is false ? false : \WP_Error)) */ function wp_clear_scheduled_hook($hook, $args = array(), $wp_error = \false) { @@ -122966,7 +122974,8 @@ function get_extended($post) * @return WP_Post|array|null Type corresponding to $output on success or null on failure. * When $output is OBJECT, a `WP_Post` instance is returned. * @phpstan-param 'raw'|'edit'|'db'|'display' $filter - * @phpstan-return ($output is 'ARRAY_A' ? array|null : ($output is 'ARRAY_N' ? array|null : \WP_Post|null)) + * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output + * @phpstan-return ($post is \WP_Post ? array|\WP_Post : array|\WP_Post|null) & ($output is 'ARRAY_A' ? array|null : ($output is 'ARRAY_N' ? array|null : \WP_Post|null)) */ function get_post($post = \null, $output = \OBJECT, $filter = 'raw') { @@ -130182,6 +130191,7 @@ function get_tax_sql($tax_query, $primary_table, $primary_id_column) * @param string $filter Optional. How to sanitize term fields. Default 'raw'. * @return WP_Term|array|WP_Error|null WP_Term instance (or array) on success, depending on the `$output` value. * WP_Error if `$taxonomy` does not exist. Null for miscellaneous failure. + * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output * @phpstan-return ($output is 'ARRAY_A' ? array|\WP_Error|null : ($output is 'ARRAY_N' ? list|\WP_Error|null : \WP_Term|\WP_Error|null)) */ function get_term($term, $taxonomy = '', $output = \OBJECT, $filter = 'raw')