Skip to content

Commit 638b3a3

Browse files
authored
Update integer ranges (#253)
Closes #252
1 parent 113b3f7 commit 638b3a3

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

functionMap.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
'__return_empty_array' => ['array{}'],
3636
'__return_empty_string' => ["''"],
3737
'__return_zero' => ['0'],
38-
'_wp_json_sanity_check' => ['T', '@phpstan-template' => 'T', 'value' => 'T', 'depth' => 'positive-int'],
38+
'_wp_json_sanity_check' => ['T', '@phpstan-template' => 'T', 'value' => 'T', 'depth' => 'int<1, max>'],
3939
'_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<T>', 'args' => 'array{screen?: string}'],
40-
'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'],
40+
'absint' => ['($maybeint is T&int<0, max> ? T : ($maybeint is int<min, -1> ? 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'],
4141
'addslashes_gpc' => ['T', '@phpstan-template' => 'T', 'gpc' => 'T'],
4242
'add_submenu_page' => [null, 'callback' => "''|callable"],
4343
'bool_from_yn' => ["(\$yn is 'y' ? true : false)"],
@@ -55,7 +55,7 @@
5555
'validate_file' => ["(\$file is '' ? 0 : (\$allowed_files is empty ? 0|1|2 : 0|1|2|3))"],
5656
'wp_die' => ['($args is array{exit: false}&array ? void : never)'],
5757
'wp_dropdown_languages' => ["(\$args is array{id: null|''}&array ? void : (\$args is array{name: null|''}&array ? void : string))"],
58-
'wp_clear_scheduled_hook' => ['(0|positive-int|($wp_error is false ? false : \WP_Error))', 'args' => $cronArgsType],
58+
'wp_clear_scheduled_hook' => ['(0|int<1, max>|($wp_error is false ? false : \WP_Error))', 'args' => $cronArgsType],
5959
'wp_generate_tag_cloud' => ["(\$args is array{format: 'array'}&array ? array<int, string> : string)"],
6060
'wp_get_schedule' => [null, 'args' => $cronArgsType],
6161
'wp_get_scheduled_event' => [null, 'args' => $cronArgsType],
@@ -147,12 +147,12 @@
147147
'term_exists' => ["(\$term is 0 ? 0 : (\$term is '' ? null : (\$taxonomy is '' ? string|null : array{term_id: string, term_taxonomy_id: string}|null)))"],
148148
'is_term' => ["(\$term is 0 ? 0 : (\$term is '' ? null : (\$taxonomy is '' ? string|null : array{term_id: string, term_taxonomy_id: string}|null)))"],
149149
'tag_exists' => ["(\$tag_name is 0 ? 0 : (\$tag_name is '' ? null : array{term_id: string, term_taxonomy_id: string}|null))"],
150-
'wp_insert_link' => ['($wp_error is false ? 0|positive-int : positive-int|\WP_Error)'],
151-
'wp_insert_category' => ['($wp_error is false ? 0|positive-int : positive-int|\WP_Error)'],
152-
'wp_insert_post' => ['($wp_error is false ? 0|positive-int : positive-int|\WP_Error)'],
153-
'wp_insert_attachment' => ['($wp_error is false ? 0|positive-int : positive-int|\WP_Error)'],
154-
'wp_update_post' => ['($wp_error is false ? 0|positive-int : positive-int|\WP_Error)'],
155-
'wp_unschedule_hook' => ['($wp_error is false ? 0|positive-int|false : 0|positive-int|\WP_Error)'],
150+
'wp_insert_link' => ['($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)'],
151+
'wp_insert_category' => ['($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)'],
152+
'wp_insert_post' => ['($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)'],
153+
'wp_insert_attachment' => ['($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)'],
154+
'wp_update_post' => ['($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)'],
155+
'wp_unschedule_hook' => ['($wp_error is false ? 0|int<1, max>|false : 0|int<1, max>|\WP_Error)'],
156156
'wp_update_comment' => ['($wp_error is false ? 0|1|false : 0|1|\WP_Error)'],
157157
'wp_set_comment_status' => ['($wp_error is false ? bool : true|\WP_Error)'],
158158
'comment_class' => ['($display is true ? void : string)'],
@@ -179,7 +179,7 @@
179179
'WP_Filesystem_SSH2::dirlist' => [$filesystemDirlistReturnType],
180180
'WP_Filesystem_ftpsockets::dirlist' => [$filesystemDirlistReturnType],
181181
'wpdb::prepare' => [null, 'query' => 'literal-string'],
182-
'wpdb::get_row' => ["null|void|(\$output is 'ARRAY_A' ? array<array-key, mixed> : (\$output is 'ARRAY_N' ? list<mixed> : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'", 'y' => '0|positive-int'],
182+
'wpdb::get_row' => ["null|void|(\$output is 'ARRAY_A' ? array<array-key, mixed> : (\$output is 'ARRAY_N' ? list<mixed> : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'", 'y' => '0|int<1, max>'],
183183
'wpdb::get_results' => ["null|(\$output is 'ARRAY_A' ? list<array<array-key, mixed>> : (\$output is 'ARRAY_N' ? list<array<int, mixed>> : (\$output is 'OBJECT_K' ? array<array-key, \stdClass> : list<\stdClass>)))", 'output' => "'OBJECT'|'OBJECT_K'|'ARRAY_A'|'ARRAY_N'"],
184184
'get_bookmark' => ["null|(\$output is 'ARRAY_A' ? array<string, mixed> : (\$output is 'ARRAY_N' ? array<int, mixed> : \stdClass))", 'output' => "'OBJECT'|'ARRAY_A'|'ARRAY_N'"],
185185
'get_categories' => ["(\$args is array{fields: 'count'}&array ? list<numeric-string> : (\$args is array{fields: 'names'|'slugs'}&array ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'}&array ? array<int, string> : (\$args is array{fields: 'id=>parent'}&array ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'}&array ? list<int> : array<int, \WP_Term>)))))"],
@@ -198,16 +198,16 @@
198198
'wp_get_post_tags' => ["(\$post_id is 0 ? array{} : ((\$args is array{fields: 'names'|'slugs'}&array ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'}&array ? array<int, string> : (\$args is array{fields: 'id=>parent'}&array ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'}&array ? list<int> : (\$args is array{fields: 'count'}&array ? numeric-string : array<int, \WP_Term>)))))|\WP_Error))"],
199199
'wp_get_post_terms' => ["(\$post_id is 0 ? array{} : (\$taxonomy is empty ? array{} : ((\$args is array{fields: 'names'|'slugs'}&array ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'}&array ? array<int, string> : (\$args is array{fields: 'id=>parent'}&array ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'}&array ? list<int> : (\$args is array{fields: 'count'}&array ? numeric-string : array<int, \WP_Term>)))))|\WP_Error)))"],
200200
'wp_get_object_terms' => ["(\$object_ids is empty ? array{} : (\$taxonomies is empty ? array{} : ((\$args is array{fields: 'names'|'slugs'}&array ? list<string> : (\$args is array{fields: 'id=>name'|'id=>slug'}&array ? array<int, string> : (\$args is array{fields: 'id=>parent'}&array ? array<int, int> : (\$args is array{fields: 'ids'|'tt_ids'}&array ? list<int> : (\$args is array{fields: 'count'}&array ? numeric-string : array<int, \WP_Term>)))))|\WP_Error)))"],
201-
'wp_json_encode' => ['non-empty-string|false', 'depth' => 'positive-int'],
201+
'wp_json_encode' => ['non-empty-string|false', 'depth' => 'int<1, max>'],
202202
'wp_parse_list' => ['($input_list is array ? array<scalar> : list<string>)'],
203203
'wp_parse_str' => [null, '@phpstan-param-out' => 'array<int|string, array|string> $result'],
204-
'size_format' => ["(\$bytes is not numeric ? false : (\$bytes is negative-int|'0' ? false : string))"],
204+
'size_format' => ["(\$bytes is not numeric ? false : (\$bytes is int<min, -1>|'0' ? false : string))"],
205205
'WP_Translations::translate' => ['($singular is null ? null : string)'],
206206
'WP_Translations::translate_plural' => ['($singular is null ? null : ($plural is null ? T : string))', '@phpstan-template T' => 'of string|null', 'singular' => 'T', 'count' => 'int'],
207207
'WP_Query' => [null, '@phpstan-property-read bool $query_vars_changed' => '', '@phpstan-property-read bool|string $query_vars_hash' => '', '@phpstan-method void init_query_flags()' => ''],
208208
'WP_Widget_Factory::$widgets' => [null, '@phpstan-var' => 'array<string, \WP_Widget>'],
209209
'WP_Widget_Factory::register' => [null, 'widget' => 'class-string<\WP_Widget>|\WP_Widget'],
210210
'WP_Widget_Factory::unregister' => [null, 'widget' => 'class-string<\WP_Widget>|\WP_Widget'],
211211
'Custom_Image_Header::show_header_selector' => [null, 'type' => "'default'|'uploaded'"],
212-
'Custom_Image_Header::set_header_image' => [null, 'choice' => 'string|array{attachment_id: positive-int, url: string, width: non-negative-int, height: non-negative-int}'],
212+
'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>}'],
213213
];

wordpress-stubs.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ public function filter_upload_tabs($tabs)
13551355
* registered for that theme; and the key of an image uploaded for that theme
13561356
* (the attachment ID of the image). Or an array of arguments: attachment_id,
13571357
* url, width, height. All are required.
1358-
* @phpstan-param string|array{attachment_id: positive-int, url: string, width: non-negative-int, height: non-negative-int} $choice
1358+
* @phpstan-param string|array{attachment_id: int<1, max>, url: string, width: int<0, max>, height: int<0, max>} $choice
13591359
* @phpstan-return void
13601360
*/
13611361
public final function set_header_image($choice)
@@ -57879,7 +57879,7 @@ public function get_var($query = \null, $x = 0, $y = 0)
5787957879
* @param int $y Optional. Row to return. Indexed from 0. Default 0.
5788057880
* @return array|object|null|void Database query result in format specified by $output or null on failure.
5788157881
* @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output
57882-
* @phpstan-param 0|positive-int $y
57882+
* @phpstan-param 0|int<1, max> $y
5788357883
* @phpstan-return null|void|($output is 'ARRAY_A' ? array<array-key, mixed> : ($output is 'ARRAY_N' ? list<mixed> : \stdClass))
5788457884
*/
5788557885
public function get_row($query = \null, $output = \OBJECT, $y = 0)
@@ -79481,7 +79481,7 @@ function get_link_to_edit($link)
7948179481
* link_rss?: string,
7948279482
* link_category?: int,
7948379483
* } $linkdata
79484-
* @phpstan-return ($wp_error is false ? 0|positive-int : positive-int|\WP_Error)
79484+
* @phpstan-return ($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)
7948579485
*/
7948679486
function wp_insert_link($linkdata, $wp_error = \false)
7948779487
{
@@ -86498,7 +86498,7 @@ function wp_create_categories($categories, $post_id = '')
8649886498
* category_nicename?: string,
8649986499
* category_parent?: int|string,
8650086500
* } $catarr
86501-
* @phpstan-return ($wp_error is false ? 0|positive-int : positive-int|\WP_Error)
86501+
* @phpstan-return ($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)
8650286502
*/
8650386503
function wp_insert_category($catarr, $wp_error = \false)
8650486504
{
@@ -100276,7 +100276,7 @@ function wp_unschedule_event($timestamp, $hook, $args = array(), $wp_error = \fa
100276100276
* events were registered with the hook and arguments combination), false or WP_Error
100277100277
* if unscheduling one or more events fail.
100278100278
* @phpstan-param list<mixed> $args
100279-
* @phpstan-return (0|positive-int|($wp_error is false ? false : \WP_Error))
100279+
* @phpstan-return (0|int<1, max>|($wp_error is false ? false : \WP_Error))
100280100280
*/
100281100281
function wp_clear_scheduled_hook($hook, $args = array(), $wp_error = \false)
100282100282
{
@@ -100299,7 +100299,7 @@ function wp_clear_scheduled_hook($hook, $args = array(), $wp_error = \false)
100299100299
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
100300100300
* @return int|false|WP_Error On success an integer indicating number of events unscheduled (0 indicates no
100301100301
* events were registered on the hook), false or WP_Error if unscheduling fails.
100302-
* @phpstan-return ($wp_error is false ? 0|positive-int|false : 0|positive-int|\WP_Error)
100302+
* @phpstan-return ($wp_error is false ? 0|int<1, max>|false : 0|int<1, max>|\WP_Error)
100303100303
*/
100304100304
function wp_unschedule_hook($hook, $wp_error = \false)
100305100305
{
@@ -107562,7 +107562,7 @@ function number_format_i18n($number, $decimals = 0)
107562107562
* @param int|string $bytes Number of bytes. Note max integer size for integers.
107563107563
* @param int $decimals Optional. Precision of number of decimal places. Default 0.
107564107564
* @return string|false Number string on success, false on failure.
107565-
* @phpstan-return ($bytes is not numeric ? false : ($bytes is negative-int|'0' ? false : string))
107565+
* @phpstan-return ($bytes is not numeric ? false : ($bytes is int<min, -1>|'0' ? false : string))
107566107566
*/
107567107567
function size_format($bytes, $decimals = 0)
107568107568
{
@@ -108849,7 +108849,7 @@ function _wp_die_process_input($message, $title = '', $args = array())
108849108849
* @param int $depth Optional. Maximum depth to walk through $value. Must be
108850108850
* greater than 0. Default 512.
108851108851
* @return string|false The JSON encoded string, or false if it cannot be encoded.
108852-
* @phpstan-param positive-int $depth
108852+
* @phpstan-param int<1, max> $depth
108853108853
* @phpstan-return non-empty-string|false
108854108854
*/
108855108855
function wp_json_encode($value, $flags = 0, $depth = 512)
@@ -108871,7 +108871,7 @@ function wp_json_encode($value, $flags = 0, $depth = 512)
108871108871
* @return mixed The sanitized data that shall be encoded to JSON.
108872108872
* @phpstan-template T
108873108873
* @phpstan-param T $value
108874-
* @phpstan-param positive-int $depth
108874+
* @phpstan-param int<1, max> $depth
108875108875
* @phpstan-return T
108876108876
*/
108877108877
function _wp_json_sanity_check($value, $depth)
@@ -109454,7 +109454,7 @@ function dead_db()
109454109454
* @return int A non-negative integer.
109455109455
* @phpstan-template T of int
109456109456
* @phpstan-param T|scalar|array|resource|null $maybeint
109457-
* @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)))))))
109457+
* @phpstan-return ($maybeint is T&int<0, max> ? T : ($maybeint is int<min, -1> ? 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>)))))))
109458109458
*/
109459109459
function absint($maybeint)
109460109460
{
@@ -128991,7 +128991,7 @@ function wp_get_recent_posts($args = array(), $output = \ARRAY_A)
128991128991
* meta_input?: array,
128992128992
* page_template?: string,
128993128993
* } $postarr
128994-
* @phpstan-return ($wp_error is false ? 0|positive-int : positive-int|\WP_Error)
128994+
* @phpstan-return ($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)
128995128995
*/
128996128996
function wp_insert_post($postarr, $wp_error = \false, $fire_after_hooks = \true)
128997128997
{
@@ -129040,7 +129040,7 @@ function wp_insert_post($postarr, $wp_error = \false, $fire_after_hooks = \true)
129040129040
* meta_input?: array,
129041129041
* page_template?: string,
129042129042
* } $postarr See wp_insert_post()
129043-
* @phpstan-return ($wp_error is false ? 0|positive-int : positive-int|\WP_Error)
129043+
* @phpstan-return ($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)
129044129044
*/
129045129045
function wp_update_post($postarr = array(), $wp_error = \false, $fire_after_hooks = \true)
129046129046
{
@@ -129506,7 +129506,7 @@ function is_local_attachment($url)
129506129506
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
129507129507
* @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true.
129508129508
* @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
129509-
* @phpstan-return ($wp_error is false ? 0|positive-int : positive-int|\WP_Error)
129509+
* @phpstan-return ($wp_error is false ? 0|int<1, max> : int<1, max>|\WP_Error)
129510129510
*/
129511129511
function wp_insert_attachment($args, $file = \false, $parent_post_id = 0, $wp_error = \false, $fire_after_hooks = \true)
129512129512
{

0 commit comments

Comments
 (0)