Skip to content

Commit f2e7f86

Browse files
authored
Mark backslashit and untrailingslashit as pure (#390)
1 parent 05ae510 commit f2e7f86

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

functionMap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
'add_users_page' => [null, 'callback' => "''|callable"],
5656
'addslashes_gpc' => ['($gpc is string ? string : array)', '@phpstan-pure' => ''],
5757
'antispambot' => [null, 'hex_encoding' => '0|1'],
58+
'backslashit' => [null, '@phpstan-pure' => ''],
5859
'block_version' => ["(\$content is '' ? 0 : 0|1)", '@phpstan-pure' => ''],
5960
'bool_from_yn' => ["(\$yn is 'y' ? true : false)", '@phpstan-pure' => ''],
6061
'build_dropdown_script_block_core_categories' => ['non-falsy-string'],
@@ -156,6 +157,7 @@
156157
'the_modified_date' => ['($display is true ? void : string)'],
157158
'the_title' => ['($display is true ? void : string|void)'],
158159
'trailingslashit' => ['non-falsy-string', '@phpstan-pure' => ''],
160+
'untrailingslashit' => [null, '@phpstan-pure' => ''],
159161
'urldecode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
160162
'urlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'],
161163
'validate_file' => ["(\$file is '' ? 0 : (\$allowed_files is empty ? 0|1|2 : 0|1|2|3))"],

tests/data/pure/backslashit.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function backslashit;
8+
use function PHPStan\Testing\assertType;
9+
10+
$value = Faker::string();
11+
12+
if (backslashit($value) === 'foo') {
13+
assertType("'foo'", backslashit($value));
14+
}
15+
16+
if (backslashit($value) !== 'foo') {
17+
assertType('string', backslashit($value));
18+
}

tests/data/pure/untrailingslashit.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function untrailingslashit;
8+
use function PHPStan\Testing\assertType;
9+
10+
$value = Faker::string();
11+
12+
if (untrailingslashit($value) === 'foo') {
13+
assertType("'foo'", untrailingslashit($value));
14+
}
15+
16+
if (untrailingslashit($value) !== 'foo') {
17+
assertType('string', untrailingslashit($value));
18+
}

wordpress-stubs.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109576,6 +109576,7 @@ function zeroise($number, $threshold)
109576109576
*
109577109577
* @param string $value Value to which backslashes will be added.
109578109578
* @return string String with backslashes inserted.
109579+
* @phpstan-pure
109579109580
*/
109580109581
function backslashit($value)
109581109582
{
@@ -109609,6 +109610,7 @@ function trailingslashit($value)
109609109610
*
109610109611
* @param string $value Value from which trailing slashes will be removed.
109611109612
* @return string String without the trailing slashes.
109613+
* @phpstan-pure
109612109614
*/
109613109615
function untrailingslashit($value)
109614109616
{

0 commit comments

Comments
 (0)