From 55057c71fd99d00111577a15f6bc3f291bb54a5c Mon Sep 17 00:00:00 2001 From: Marian <42134098+IanDelMar@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:04:07 +0200 Subject: [PATCH] Update integer ranges Closes #252 --- functionMap.php | 26 +++++++++++++------------- wordpress-stubs.php | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/functionMap.php b/functionMap.php index 3162de3..04c90f6 100644 --- a/functionMap.php +++ b/functionMap.php @@ -35,9 +35,9 @@ '__return_empty_array' => ['array{}'], '__return_empty_string' => ["''"], '__return_zero' => ['0'], - '_wp_json_sanity_check' => ['T', '@phpstan-template' => 'T', 'value' => 'T', 'depth' => 'positive-int'], + '_wp_json_sanity_check' => ['T', '@phpstan-template' => 'T', 'value' => 'T', 'depth' => 'int<1, max>'], '_get_list_table' => ["(\$class_name is 'WP_Posts_List_Table'|'WP_Media_List_Table'|'WP_Terms_List_Table'|'WP_Users_List_Table'|'WP_Comments_List_Table'|'WP_Post_Comments_List_Table'|'WP_Links_List_Table'|'WP_Plugin_Install_List_Table'|'WP_Themes_List_Table'|'WP_Theme_Install_List_Table'|'WP_Plugins_List_Table'|'WP_Application_Passwords_List_Table'|'WP_MS_Sites_List_Table'|'WP_MS_Users_List_Table'|'WP_MS_Themes_List_Table'|'WP_Privacy_Data_Export_Requests_List_Table'|'WP_Privacy_Data_Removal_Requests_List_Table' ? T : false)", '@phpstan-template' => 'T', 'class_name' => 'class-string', 'args' => 'array{screen?: string}'], - 'absint' => ['($maybeint is T&non-negative-int ? T : ($maybeint is negative-int ? positive-int : ($maybeint is empty ? 0 : ($maybeint is numeric-string ? non-negative-int : ($maybeint is string ? 0 : ($maybeint is true|non-empty-array ? 1 : ($maybeint is bool ? 0|1 : non-negative-int)))))))', '@phpstan-template T' => 'of int', 'maybeint' => 'T|scalar|array|resource|null'], + 'absint' => ['($maybeint is T&int<0, max> ? T : ($maybeint is int ? int<1, max> : ($maybeint is empty ? 0 : ($maybeint is numeric-string ? int<0, max> : ($maybeint is string ? 0 : ($maybeint is true|non-empty-array ? 1 : ($maybeint is bool ? 0|1 : int<0, max>)))))))', '@phpstan-template T' => 'of int', 'maybeint' => 'T|scalar|array|resource|null'], 'addslashes_gpc' => ['T', '@phpstan-template' => 'T', 'gpc' => 'T'], 'add_submenu_page' => [null, 'callback' => "''|callable"], 'bool_from_yn' => ["(\$yn is 'y' ? true : false)"], @@ -55,7 +55,7 @@ 'validate_file' => ["(\$file is '' ? 0 : (\$allowed_files is empty ? 0|1|2 : 0|1|2|3))"], 'wp_die' => ['($args is array{exit: false}&array ? void : never)'], 'wp_dropdown_languages' => ["(\$args is array{id: null|''}&array ? void : (\$args is array{name: null|''}&array ? void : string))"], - 'wp_clear_scheduled_hook' => ['(0|positive-int|($wp_error is false ? false : \WP_Error))', 'args' => $cronArgsType], + 'wp_clear_scheduled_hook' => ['(0|int<1, max>|($wp_error is false ? false : \WP_Error))', 'args' => $cronArgsType], 'wp_generate_tag_cloud' => ["(\$args is array{format: 'array'}&array ? array : string)"], 'wp_get_schedule' => [null, 'args' => $cronArgsType], 'wp_get_scheduled_event' => [null, 'args' => $cronArgsType], @@ -147,12 +147,12 @@ 'term_exists' => ["(\$term is 0 ? 0 : (\$term is '' ? null : (\$taxonomy is '' ? string|null : array{term_id: string, term_taxonomy_id: string}|null)))"], 'is_term' => ["(\$term is 0 ? 0 : (\$term is '' ? null : (\$taxonomy is '' ? string|null : array{term_id: string, term_taxonomy_id: string}|null)))"], 'tag_exists' => ["(\$tag_name is 0 ? 0 : (\$tag_name is '' ? null : array{term_id: string, term_taxonomy_id: string}|null))"], - 'wp_insert_link' => ['($wp_error is false ? 0|positive-int : positive-int|\WP_Error)'], - 'wp_insert_category' => ['($wp_error is false ? 0|positive-int : positive-int|\WP_Error)'], - 'wp_insert_post' => ['($wp_error is false ? 0|positive-int : positive-int|\WP_Error)'], - 'wp_insert_attachment' => ['($wp_error is false ? 0|positive-int : positive-int|\WP_Error)'], - 'wp_update_post' => ['($wp_error is false ? 0|positive-int : positive-int|\WP_Error)'], - 'wp_unschedule_hook' => ['($wp_error is false ? 0|positive-int|false : 0|positive-int|\WP_Error)'], + 'wp_insert_link' => ['($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)'], + 'wp_insert_category' => ['($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)'], + 'wp_insert_post' => ['($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)'], + 'wp_insert_attachment' => ['($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)'], + 'wp_update_post' => ['($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)'], + 'wp_unschedule_hook' => ['($wp_error is false ? 0|int<1, max>|false : 0|int<1, max>|\WP_Error)'], 'wp_update_comment' => ['($wp_error is false ? 0|1|false : 0|1|\WP_Error)'], 'wp_set_comment_status' => ['($wp_error is false ? bool : true|\WP_Error)'], 'comment_class' => ['($display is true ? void : string)'], @@ -179,7 +179,7 @@ 'WP_Filesystem_SSH2::dirlist' => [$filesystemDirlistReturnType], 'WP_Filesystem_ftpsockets::dirlist' => [$filesystemDirlistReturnType], 'wpdb::prepare' => [null, 'query' => 'literal-string'], - 'wpdb::get_row' => ["null|void|(\$output is 'ARRAY_A' ? array : (\$output is 'ARRAY_N' ? list : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'", 'y' => '0|positive-int'], + 'wpdb::get_row' => ["null|void|(\$output is 'ARRAY_A' ? array : (\$output is 'ARRAY_N' ? list : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'", 'y' => '0|int<1, max>'], 'wpdb::get_results' => ["null|(\$output is 'ARRAY_A' ? list> : (\$output is 'ARRAY_N' ? list> : (\$output is 'OBJECT_K' ? array : list<\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_categories' => ["(\$args is array{fields: 'count'}&array ? list : (\$args is array{fields: 'names'|'slugs'}&array ? list : (\$args is array{fields: 'id=>name'|'id=>slug'}&array ? array : (\$args is array{fields: 'id=>parent'}&array ? array : (\$args is array{fields: 'ids'|'tt_ids'}&array ? list : array)))))"], @@ -198,10 +198,10 @@ 'wp_get_post_tags' => ["(\$post_id is 0 ? array{} : ((\$args is array{fields: 'names'|'slugs'}&array ? list : (\$args is array{fields: 'id=>name'|'id=>slug'}&array ? array : (\$args is array{fields: 'id=>parent'}&array ? array : (\$args is array{fields: 'ids'|'tt_ids'}&array ? list : (\$args is array{fields: 'count'}&array ? numeric-string : array)))))|\WP_Error))"], 'wp_get_post_terms' => ["(\$post_id is 0 ? array{} : (\$taxonomy is empty ? array{} : ((\$args is array{fields: 'names'|'slugs'}&array ? list : (\$args is array{fields: 'id=>name'|'id=>slug'}&array ? array : (\$args is array{fields: 'id=>parent'}&array ? array : (\$args is array{fields: 'ids'|'tt_ids'}&array ? list : (\$args is array{fields: 'count'}&array ? numeric-string : array)))))|\WP_Error)))"], 'wp_get_object_terms' => ["(\$object_ids is empty ? array{} : (\$taxonomies is empty ? array{} : ((\$args is array{fields: 'names'|'slugs'}&array ? list : (\$args is array{fields: 'id=>name'|'id=>slug'}&array ? array : (\$args is array{fields: 'id=>parent'}&array ? array : (\$args is array{fields: 'ids'|'tt_ids'}&array ? list : (\$args is array{fields: 'count'}&array ? numeric-string : array)))))|\WP_Error)))"], - 'wp_json_encode' => ['non-empty-string|false', 'depth' => 'positive-int'], + 'wp_json_encode' => ['non-empty-string|false', 'depth' => 'int<1, max>'], 'wp_parse_list' => ['($input_list is array ? array : list)'], 'wp_parse_str' => [null, '@phpstan-param-out' => 'array $result'], - 'size_format' => ["(\$bytes is not numeric ? false : (\$bytes is negative-int|'0' ? false : string))"], + 'size_format' => ["(\$bytes is not numeric ? false : (\$bytes is int|'0' ? false : string))"], 'WP_Translations::translate' => ['($singular is null ? null : string)'], 'WP_Translations::translate_plural' => ['($singular is null ? null : ($plural is null ? T : string))', '@phpstan-template T' => 'of string|null', 'singular' => 'T', 'count' => 'int'], 'WP_Query' => [null, '@phpstan-property-read bool $query_vars_changed' => '', '@phpstan-property-read bool|string $query_vars_hash' => '', '@phpstan-method void init_query_flags()' => ''], @@ -209,5 +209,5 @@ 'WP_Widget_Factory::register' => [null, 'widget' => 'class-string<\WP_Widget>|\WP_Widget'], 'WP_Widget_Factory::unregister' => [null, 'widget' => 'class-string<\WP_Widget>|\WP_Widget'], 'Custom_Image_Header::show_header_selector' => [null, 'type' => "'default'|'uploaded'"], - 'Custom_Image_Header::set_header_image' => [null, 'choice' => 'string|array{attachment_id: positive-int, url: string, width: non-negative-int, height: non-negative-int}'], + 'Custom_Image_Header::set_header_image' => [null, 'choice' => 'string|array{attachment_id: int<1, max>, url: string, width: int<0, max>, height: int<0, max>}'], ]; diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 1dc60ea..ca5a790 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -1355,7 +1355,7 @@ public function filter_upload_tabs($tabs) * registered for that theme; and the key of an image uploaded for that theme * (the attachment ID of the image). Or an array of arguments: attachment_id, * url, width, height. All are required. - * @phpstan-param string|array{attachment_id: positive-int, url: string, width: non-negative-int, height: non-negative-int} $choice + * @phpstan-param string|array{attachment_id: int<1, max>, url: string, width: int<0, max>, height: int<0, max>} $choice * @phpstan-return void */ public final function set_header_image($choice) @@ -57879,7 +57879,7 @@ public function get_var($query = \null, $x = 0, $y = 0) * @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-param 0|int<1, max> $y * @phpstan-return null|void|($output is 'ARRAY_A' ? array : ($output is 'ARRAY_N' ? list : \stdClass)) */ public function get_row($query = \null, $output = \OBJECT, $y = 0) @@ -79481,7 +79481,7 @@ function get_link_to_edit($link) * link_rss?: string, * link_category?: int, * } $linkdata - * @phpstan-return ($wp_error is false ? 0|positive-int : positive-int|\WP_Error) + * @phpstan-return ($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error) */ function wp_insert_link($linkdata, $wp_error = \false) { @@ -86498,7 +86498,7 @@ function wp_create_categories($categories, $post_id = '') * category_nicename?: string, * category_parent?: int|string, * } $catarr - * @phpstan-return ($wp_error is false ? 0|positive-int : positive-int|\WP_Error) + * @phpstan-return ($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error) */ function wp_insert_category($catarr, $wp_error = \false) { @@ -100276,7 +100276,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 (0|positive-int|($wp_error is false ? false : \WP_Error)) + * @phpstan-return (0|int<1, max>|($wp_error is false ? false : \WP_Error)) */ function wp_clear_scheduled_hook($hook, $args = array(), $wp_error = \false) { @@ -100299,7 +100299,7 @@ function wp_clear_scheduled_hook($hook, $args = array(), $wp_error = \false) * @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. * @return int|false|WP_Error On success an integer indicating number of events unscheduled (0 indicates no * events were registered on the hook), false or WP_Error if unscheduling fails. - * @phpstan-return ($wp_error is false ? 0|positive-int|false : 0|positive-int|\WP_Error) + * @phpstan-return ($wp_error is false ? 0|int<1, max>|false : 0|int<1, max>|\WP_Error) */ function wp_unschedule_hook($hook, $wp_error = \false) { @@ -107562,7 +107562,7 @@ function number_format_i18n($number, $decimals = 0) * @param int|string $bytes Number of bytes. Note max integer size for integers. * @param int $decimals Optional. Precision of number of decimal places. Default 0. * @return string|false Number string on success, false on failure. - * @phpstan-return ($bytes is not numeric ? false : ($bytes is negative-int|'0' ? false : string)) + * @phpstan-return ($bytes is not numeric ? false : ($bytes is int|'0' ? false : string)) */ function size_format($bytes, $decimals = 0) { @@ -108849,7 +108849,7 @@ function _wp_die_process_input($message, $title = '', $args = array()) * @param int $depth Optional. Maximum depth to walk through $value. Must be * greater than 0. Default 512. * @return string|false The JSON encoded string, or false if it cannot be encoded. - * @phpstan-param positive-int $depth + * @phpstan-param int<1, max> $depth * @phpstan-return non-empty-string|false */ function wp_json_encode($value, $flags = 0, $depth = 512) @@ -108871,7 +108871,7 @@ function wp_json_encode($value, $flags = 0, $depth = 512) * @return mixed The sanitized data that shall be encoded to JSON. * @phpstan-template T * @phpstan-param T $value - * @phpstan-param positive-int $depth + * @phpstan-param int<1, max> $depth * @phpstan-return T */ function _wp_json_sanity_check($value, $depth) @@ -109454,7 +109454,7 @@ function dead_db() * @return int A non-negative integer. * @phpstan-template T of int * @phpstan-param T|scalar|array|resource|null $maybeint - * @phpstan-return ($maybeint is T&non-negative-int ? T : ($maybeint is negative-int ? positive-int : ($maybeint is empty ? 0 : ($maybeint is numeric-string ? non-negative-int : ($maybeint is string ? 0 : ($maybeint is true|non-empty-array ? 1 : ($maybeint is bool ? 0|1 : non-negative-int))))))) + * @phpstan-return ($maybeint is T&int<0, max> ? T : ($maybeint is int ? int<1, max> : ($maybeint is empty ? 0 : ($maybeint is numeric-string ? int<0, max> : ($maybeint is string ? 0 : ($maybeint is true|non-empty-array ? 1 : ($maybeint is bool ? 0|1 : int<0, max>))))))) */ function absint($maybeint) { @@ -128991,7 +128991,7 @@ function wp_get_recent_posts($args = array(), $output = \ARRAY_A) * meta_input?: array, * page_template?: string, * } $postarr - * @phpstan-return ($wp_error is false ? 0|positive-int : positive-int|\WP_Error) + * @phpstan-return ($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error) */ function wp_insert_post($postarr, $wp_error = \false, $fire_after_hooks = \true) { @@ -129040,7 +129040,7 @@ function wp_insert_post($postarr, $wp_error = \false, $fire_after_hooks = \true) * meta_input?: array, * page_template?: string, * } $postarr See wp_insert_post() - * @phpstan-return ($wp_error is false ? 0|positive-int : positive-int|\WP_Error) + * @phpstan-return ($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error) */ function wp_update_post($postarr = array(), $wp_error = \false, $fire_after_hooks = \true) { @@ -129506,7 +129506,7 @@ function is_local_attachment($url) * @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. * @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true. * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. - * @phpstan-return ($wp_error is false ? 0|positive-int : positive-int|\WP_Error) + * @phpstan-return ($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error) */ function wp_insert_attachment($args, $file = \false, $parent_post_id = 0, $wp_error = \false, $fire_after_hooks = \true) {