From dd0b3f61a6bb31e40005122440f7071e777b02e4 Mon Sep 17 00:00:00 2001 From: Marian <42134098+IanDelMar@users.noreply.github.com> Date: Sun, 7 Sep 2025 04:23:31 +0200 Subject: [PATCH] Narrow parameter type for register_post_type --- functionMap.php | 1 + tests/ParameterTypeTest.php | 16 ++++++++++++++++ tests/data/param/register-post-type.php | 24 ++++++++++++++++++++++++ wordpress-stubs.php | 1 + 4 files changed, 42 insertions(+) create mode 100644 tests/data/param/register-post-type.php diff --git a/functionMap.php b/functionMap.php index 0a461ef..6c2805d 100644 --- a/functionMap.php +++ b/functionMap.php @@ -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'], + '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'], diff --git a/tests/ParameterTypeTest.php b/tests/ParameterTypeTest.php index 3ebf88a..caad62e 100644 --- a/tests/ParameterTypeTest.php +++ b/tests/ParameterTypeTest.php @@ -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( diff --git a/tests/data/param/register-post-type.php b/tests/data/param/register-post-type.php new file mode 100644 index 0000000..6c93928 --- /dev/null +++ b/tests/data/param/register-post-type.php @@ -0,0 +1,24 @@ +