From 3c1d56641198fdee0e159d6f0612adcf21d01dad Mon Sep 17 00:00:00 2001 From: Marian <42134098+IanDelMar@users.noreply.github.com> Date: Wed, 29 Oct 2025 06:41:32 +0100 Subject: [PATCH 1/2] Narrow $hook_name type in do_action/apply_filters --- functionMap.php | 6 ++++++ tests/ParameterTypeTest.php | 30 ++++++++++++++++++++++++++++++ tests/data/param/apply-filters.php | 20 ++++++++++++++++++++ tests/data/param/do-action.php | 20 ++++++++++++++++++++ wordpress-stubs.php | 6 ++++++ 5 files changed, 82 insertions(+) create mode 100644 tests/data/param/apply-filters.php create mode 100644 tests/data/param/do-action.php diff --git a/functionMap.php b/functionMap.php index b4ee94b..af34054 100644 --- a/functionMap.php +++ b/functionMap.php @@ -55,6 +55,9 @@ 'add_users_page' => [null, 'callback' => "''|callable"], 'addslashes_gpc' => ['($gpc is string ? string : array)', '@phpstan-pure' => ''], 'antispambot' => [null, 'hex_encoding' => '0|1'], + 'apply_filters' => [null, 'hook_name' => 'non-empty-string'], + 'apply_filters_ref_array' => [null, 'hook_name' => 'non-empty-string'], + 'apply_filters_deprecated' => [null, 'hook_name' => 'non-empty-string'], 'backslashit' => [null, '@phpstan-pure' => ''], 'block_version' => ["(\$content is '' ? 0 : 0|1)", '@phpstan-pure' => ''], 'bool_from_yn' => ["(\$yn is 'y' ? true : false)", '@phpstan-pure' => ''], @@ -67,6 +70,9 @@ 'current_time' => ["(\$type is 'timestamp'|'U' ? int : string)"], 'did_action' => ['int<0, max>'], 'did_filter' => ['int<0, max>'], + 'do_action' => ['void', 'hook_name' => 'non-empty-string'], + 'do_action_ref_array' => ['void', 'hook_name' => 'non-empty-string'], + 'do_action_deprecated' => ['void', 'hook_name' => 'non-empty-string'], 'edit_link' => ['int<0, max>'], 'edit_term_link' => ['($display is true ? void : string|void)'], 'get_approved_comments' => ["(\$args is array{count: true}&array ? int : (\$args is array{fields: 'ids'}&array ? array : array))"], diff --git a/tests/ParameterTypeTest.php b/tests/ParameterTypeTest.php index 883c3fe..180001b 100644 --- a/tests/ParameterTypeTest.php +++ b/tests/ParameterTypeTest.php @@ -83,6 +83,21 @@ public function testAntispambot(): void ); } + public function testApplyFilters(): void + { + $this->analyse( + __DIR__ . '/data/param/apply-filters.php', + [ + ["Parameter #1 \$hook_name of function apply_filters expects non-empty-string, '' given.", 8], + ["Parameter #1 \$hook_name of function apply_filters_ref_array expects non-empty-string, '' given.", 9], + ["Parameter #1 \$hook_name of function apply_filters_deprecated expects non-empty-string, '' given.", 10], + ['Parameter #1 \$hook_name of function apply_filters expects non-empty-string, string given.', 13], + ['Parameter #1 \$hook_name of function apply_filters_ref_array expects non-empty-string, string given.', 14], + ['Parameter #1 \$hook_name of function apply_filters_deprecated expects non-empty-string, string given.', 15], + ] + ); + } + public function testBookmarks(): void { $field = "'link_category'|'link_description'|'link_id'|'link_image'|'link_name'|'link_notes'|'link_owner'|'link_rating'|'link_rel'|'link_rss'|'link_target'|'link_updated'|'link_url'|'link_visible'"; @@ -124,6 +139,21 @@ public function testCheckAjaxReferer(): void ); } + public function testDoAction(): void + { + $this->analyse( + __DIR__ . '/data/param/do-action.php', + [ + ["Parameter #1 \$hook_name of function do_action expects non-empty-string, '' given.", 8], + ["Parameter #1 \$hook_name of function do_action_ref_array expects non-empty-string, '' given.", 9], + ["Parameter #1 \$hook_name of function do_action_deprecated expects non-empty-string, '' given.", 10], + ['Parameter #1 \$hook_name of function do_action expects non-empty-string, string given.', 13], + ['Parameter #1 \$hook_name of function do_action_ref_array expects non-empty-string, string given.', 14], + ['Parameter #1 \$hook_name of function do_action_deprecated expects non-empty-string, string given.', 15], + ] + ); + } + public function testRegisterNavMenus(): void { $this->analyse( diff --git a/tests/data/param/apply-filters.php b/tests/data/param/apply-filters.php new file mode 100644 index 0000000..b5dbcfd --- /dev/null +++ b/tests/data/param/apply-filters.php @@ -0,0 +1,20 @@ + Date: Wed, 29 Oct 2025 06:45:03 +0100 Subject: [PATCH 2/2] Update ParameterTypeTest.php --- tests/ParameterTypeTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ParameterTypeTest.php b/tests/ParameterTypeTest.php index 180001b..19020c7 100644 --- a/tests/ParameterTypeTest.php +++ b/tests/ParameterTypeTest.php @@ -91,9 +91,9 @@ public function testApplyFilters(): void ["Parameter #1 \$hook_name of function apply_filters expects non-empty-string, '' given.", 8], ["Parameter #1 \$hook_name of function apply_filters_ref_array expects non-empty-string, '' given.", 9], ["Parameter #1 \$hook_name of function apply_filters_deprecated expects non-empty-string, '' given.", 10], - ['Parameter #1 \$hook_name of function apply_filters expects non-empty-string, string given.', 13], - ['Parameter #1 \$hook_name of function apply_filters_ref_array expects non-empty-string, string given.', 14], - ['Parameter #1 \$hook_name of function apply_filters_deprecated expects non-empty-string, string given.', 15], + ['Parameter #1 $hook_name of function apply_filters expects non-empty-string, string given.', 13], + ['Parameter #1 $hook_name of function apply_filters_ref_array expects non-empty-string, string given.', 14], + ['Parameter #1 $hook_name of function apply_filters_deprecated expects non-empty-string, string given.', 15], ] ); } @@ -147,9 +147,9 @@ public function testDoAction(): void ["Parameter #1 \$hook_name of function do_action expects non-empty-string, '' given.", 8], ["Parameter #1 \$hook_name of function do_action_ref_array expects non-empty-string, '' given.", 9], ["Parameter #1 \$hook_name of function do_action_deprecated expects non-empty-string, '' given.", 10], - ['Parameter #1 \$hook_name of function do_action expects non-empty-string, string given.', 13], - ['Parameter #1 \$hook_name of function do_action_ref_array expects non-empty-string, string given.', 14], - ['Parameter #1 \$hook_name of function do_action_deprecated expects non-empty-string, string given.', 15], + ['Parameter #1 $hook_name of function do_action expects non-empty-string, string given.', 13], + ['Parameter #1 $hook_name of function do_action_ref_array expects non-empty-string, string given.', 14], + ['Parameter #1 $hook_name of function do_action_deprecated expects non-empty-string, string given.', 15], ] ); }