Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
'rest_ensure_response' => ['($response is \WP_Error ? \WP_Error : \WP_REST_Response)'],
'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'"],
'sanitize_category' => ['T', '@phpstan-template' => 'T of array|object', 'category' => 'T'],
'sanitize_post' => ['T', '@phpstan-template' => 'T of array|object', 'post' => 'T'],
'sanitize_post' => ['(T is \WP_Post ? \WP_Post : (T is object ? object : (T is array ? array : T)))', '@phpstan-template T' => 'of mixed', 'post' => 'T'],
'sanitize_sql_orderby' => ['(T is non-falsy-string ? T|false : false)', '@phpstan-template T' => 'of string', 'orderby' => 'T'],
'sanitize_term' => ['T', '@phpstan-template' => 'T of array|object', 'term' => 'T'],
'sanitize_title_with_dashes' => ['lowercase-string', 'context' => "'display'|'save'"],
Expand Down
25 changes: 25 additions & 0 deletions tests/data/return/sanitize-post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use stdClass;

use function sanitize_post;
use function PHPStan\Testing\assertType;

assertType('WP_Post', sanitize_post(Faker::wpPost(), Faker::string()));
assertType('object', sanitize_post(Faker::object(), Faker::string()));
assertType('object', sanitize_post(new stdClass(), Faker::string()));
assertType('array', sanitize_post(Faker::array(), Faker::string()));
assertType('array', sanitize_post(Faker::strArray(), Faker::string()));
assertType('array', sanitize_post(Faker::intArray(), Faker::string()));
assertType('array', sanitize_post(Faker::array(Faker::string()), Faker::string()));

// Incorrect type of $post is returned as-is.
assertType("'foo'", sanitize_post('foo', Faker::string()));
assertType('123', sanitize_post(123, Faker::string()));
assertType('string', sanitize_post(Faker::string(), Faker::string()));
assertType('int', sanitize_post(Faker::int(), Faker::string()));
assertType('bool', sanitize_post(Faker::bool(), Faker::string()));
4 changes: 2 additions & 2 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -132335,9 +132335,9 @@ function is_sticky($post_id = 0)
* @return object|WP_Post|array The now sanitized post object or array (will be the
* same type as `$post`).
* @phpstan-param 'raw'|'edit'|'db'|'display'|'attribute'|'js' $context
* @phpstan-template T of array|object
* @phpstan-template T of mixed
* @phpstan-param T $post
* @phpstan-return T
* @phpstan-return (T is \WP_Post ? \WP_Post : (T is object ? object : (T is array ? array : T)))
*/
function sanitize_post($post, $context = 'display')
{
Expand Down