Skip to content

Commit 945a6da

Browse files
authored
Narrow the parameter type for antispambot() (#386)
1 parent ba070da commit 945a6da

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

functionMap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
'add_theme_page' => [null, 'callback' => "''|callable"],
5555
'add_users_page' => [null, 'callback' => "''|callable"],
5656
'addslashes_gpc' => ['($gpc is string ? string : array)', '@phpstan-pure' => ''],
57+
'antispambot' => [null, 'hex_encoding' => '0|1'],
5758
'block_version' => ["(\$content is '' ? 0 : 0|1)", '@phpstan-pure' => ''],
5859
'bool_from_yn' => ["(\$yn is 'y' ? true : false)", '@phpstan-pure' => ''],
5960
'build_dropdown_script_block_core_categories' => ['non-falsy-string'],

tests/ParameterTypeTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ public function testAddShortcode(): void
6363
);
6464
}
6565

66+
public function testAntispambot(): void
67+
{
68+
$this->analyse(
69+
__DIR__ . '/data/param/antispambot.php',
70+
[
71+
['Parameter #2 $hex_encoding of function antispambot expects 0|1, 42 given.', 12],
72+
['Parameter #2 $hex_encoding of function antispambot expects 0|1, -42 given.', 13],
73+
['Parameter #2 $hex_encoding of function antispambot expects 0|1, string given.', 14],
74+
// Maybes
75+
['Parameter #2 $hex_encoding of function antispambot expects 0|1, int given.', 17],
76+
]
77+
);
78+
}
79+
6680
public function testBookmarks(): void
6781
{
6882
$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'";

tests/data/param/antispambot.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function antispambot;
8+
9+
$email = Faker::string();
10+
11+
// Incorrect $hex_encoding
12+
antispambot($email, 42);
13+
antispambot($email, -42);
14+
antispambot($email, Faker::string());
15+
16+
// Maybe incorrect $hex_encoding
17+
antispambot($email, Faker::int());
18+
19+
// Correct $hex_encoding
20+
antispambot($email, 0);
21+
antispambot($email, 1);

wordpress-stubs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109704,6 +109704,7 @@ function urldecode_deep($value)
109704109704
* @param string $email_address Email address.
109705109705
* @param int $hex_encoding Optional. Set to 1 to enable hex encoding.
109706109706
* @return string Converted email address.
109707+
* @phpstan-param 0|1 $hex_encoding
109707109708
*/
109708109709
function antispambot($email_address, $hex_encoding = 0)
109709109710
{

0 commit comments

Comments
 (0)