From 427bfedd12afcfbb9819c01eb4589ada47bc8f55 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Wed, 18 Sep 2024 01:24:25 +0200 Subject: [PATCH] Narrow return type & add param type for wp_json_encode() (#227) * Narrow return typ & add param type for wp_json_encode() * Fix cs issue --- functionMap.php | 1 + wordpress-stubs.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/functionMap.php b/functionMap.php index c344817..a4ca9aa 100644 --- a/functionMap.php +++ b/functionMap.php @@ -188,6 +188,7 @@ 'wp_get_post_tags' => ["(\$post_id is 0 ? array{} : ((\$args is array{fields: 'names'|'slugs'} ? list : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array : (\$args is array{fields: 'id=>parent'} ? array : (\$args is array{fields: 'ids'|'tt_ids'} ? list : (\$args is array{fields: 'count'} ? numeric-string : array)))))|\WP_Error))"], 'wp_get_post_terms' => ["(\$post_id is 0 ? array{} : (\$taxonomy is empty ? array{} : ((\$args is array{fields: 'names'|'slugs'} ? list : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array : (\$args is array{fields: 'id=>parent'} ? array : (\$args is array{fields: 'ids'|'tt_ids'} ? list : (\$args is array{fields: 'count'} ? numeric-string : array)))))|\WP_Error)))"], 'wp_get_object_terms' => ["(\$object_ids is empty ? array{} : (\$taxonomies is empty ? array{} : ((\$args is array{fields: 'names'|'slugs'} ? list : (\$args is array{fields: 'id=>name'|'id=>slug'} ? array : (\$args is array{fields: 'id=>parent'} ? array : (\$args is array{fields: 'ids'|'tt_ids'} ? list : (\$args is array{fields: 'count'} ? numeric-string : array)))))|\WP_Error)))"], + 'wp_json_encode' => ['non-empty-string|false', 'depth' => 'positive-int'], '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))"], diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 4262d47..8ecab90 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -108899,6 +108899,8 @@ 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-return non-empty-string|false */ function wp_json_encode($value, $flags = 0, $depth = 512) {