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
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
'previous_posts' => ['($display is true ? void : string)'],
'rawurlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
'register_nav_menus' => [null, 'locations' => 'array<string, string>'],
'register_post_type' => [null, 'post_type' => 'lowercase-string&non-empty-string'],
'render_block_core_categories' => ['non-falsy-string'],
'rest_authorization_required_code' => ['401|403'],
'rest_sanitize_boolean' => ["(T is bool ? T : (T is ''|'false'|'FALSE'|'0'|0 ? false : true))", '@phpstan-template T' => 'of bool|string|int', 'value' => 'T'],
Expand Down
16 changes: 16 additions & 0 deletions tests/ParameterTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ public function testRegisterNavMenus(): void
);
}

public function testRegisterPostType(): void
{
$this->analyse(
__DIR__ . '/data/param/register-post-type.php',
[
["Parameter #1 \$post_type of function register_post_type expects lowercase-string&non-empty-string, '' given.", 13],
["Parameter #1 \$post_type of function register_post_type expects lowercase-string&non-empty-string, 'PostType' given.", 14],
// Maybes
['Parameter #1 $post_type of function register_post_type expects lowercase-string&non-empty-string, non-empty-string given.', 17],
['Parameter #1 $post_type of function register_post_type expects lowercase-string&non-empty-string, non-falsy-string given.', 18],
['Parameter #1 $post_type of function register_post_type expects lowercase-string&non-empty-string, lowercase-string given.', 19],
['Parameter #1 $post_type of function register_post_type expects lowercase-string&non-empty-string, string given.', 20],
]
);
}

public function testWpdbGetRow(): void
{
$this->analyse(
Expand Down
24 changes: 24 additions & 0 deletions tests/data/param/register-post-type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function register_post_type;

$empty = '';
$containsUppercases = 'PostType';

// Incorrect $post_type
register_post_type($empty, Faker::array());
register_post_type($containsUppercases, Faker::array());

// Maybe incorrect $post_type
register_post_type(Faker::nonEmptyString(), Faker::array());
register_post_type(Faker::nonFalsyString(), Faker::array());
register_post_type(Faker::lowercaseString(), Faker::array());
register_post_type(Faker::string(), Faker::array());

// Correct $post_type
register_post_type('post_type', Faker::array());
register_post_type(Faker::intersection(Faker::lowercaseString(), Faker::nonEmptyString()), Faker::array());
1 change: 1 addition & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -131627,6 +131627,7 @@ function get_post_types($args = array(), $output = 'names', $operator = 'and')
* _builtin?: bool,
* _edit_link?: string,
* } $args
* @phpstan-param lowercase-string&non-empty-string $post_type
*/
function register_post_type($post_type, $args = array())
{
Expand Down