Skip to content

Commit dba66d7

Browse files
authored
Mark rest_sanitize_boolean as pure (#387)
1 parent 945a6da commit dba66d7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

functionMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
'register_post_type' => [null, 'post_type' => 'lowercase-string&non-empty-string'],
131131
'render_block_core_categories' => ['non-falsy-string'],
132132
'rest_authorization_required_code' => ['401|403'],
133-
'rest_sanitize_boolean' => ["(T is bool ? T : (T is ''|'false'|'FALSE'|'0'|0 ? false : true))", '@phpstan-template T' => 'of bool|string|int', 'value' => 'T'],
133+
'rest_sanitize_boolean' => ["(T is bool ? T : (T is ''|'false'|'FALSE'|'0'|0 ? false : true))", '@phpstan-template T' => 'of bool|string|int', 'value' => 'T', '@phpstan-pure' => ''],
134134
'rest_ensure_response' => ['($response is \WP_Error ? \WP_Error : \WP_REST_Response)'],
135135
'sanitize_bookmark_field' => ['array<int, int>|int|string', 'field' => "'link_id'|'link_url'|'link_name'|'link_image'|'link_target'|'link_description'|'link_visible'|'link_owner'|'link_rating'|'link_updated'|'link_rel'|'link_notes'|'link_rss'|'link_category'"],
136136
'sanitize_category' => ['T', '@phpstan-template' => 'T of array|object', 'category' => 'T'],
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function rest_sanitize_boolean;
8+
use function PHPStan\Testing\assertType;
9+
10+
$toSanitize = Faker::mixed();
11+
12+
assertType('bool', rest_sanitize_boolean($toSanitize));
13+
14+
if (rest_sanitize_boolean($toSanitize)) {
15+
assertType('true', rest_sanitize_boolean($toSanitize));
16+
}
17+
18+
if (! rest_sanitize_boolean($toSanitize)) {
19+
assertType('false', rest_sanitize_boolean($toSanitize));
20+
}

wordpress-stubs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135481,6 +135481,7 @@ function rest_is_ip_address($ip)
135481135481
* @return bool Returns the proper associated boolean value.
135482135482
* @phpstan-template T of bool|string|int
135483135483
* @phpstan-param T $value
135484+
* @phpstan-pure
135484135485
* @phpstan-return (T is bool ? T : (T is ''|'false'|'FALSE'|'0'|0 ? false : true))
135485135486
*/
135486135487
function rest_sanitize_boolean($value)

0 commit comments

Comments
 (0)