Skip to content

Commit 349dc82

Browse files
path_is_absolute: narrow return type and assert param type (#482)
Co-authored-by: Viktor Szépe <viktor@szepe.net>
1 parent b6737c8 commit 349dc82

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

functionMap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
'newblog_notify_siteadmin' => [null, 'deprecated' => "''"],
182182
'next_posts' => ['($display is true ? void : string)'],
183183
'paginate_links' => ["(\$args is array{total: int<min, 1>}&array ? void : (\$args is array{type: 'array'}&array ? list<string> : string))"],
184+
'path_is_absolute' => ['($path is non-falsy-string ? bool : false)', '@phpstan-assert-if-true =non-falsy-string $path' => ''],
184185
'path_join' => ['non-falsy-string'],
185186
'post_type_archive_title' => ['($display is true ? void : string|void)'],
186187
'prep_atom_text_construct' => ["array{'html'|'text'|'xhtml', string}"],
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function path_is_absolute;
8+
use function PHPStan\Testing\assertType;
9+
10+
$path = Faker::string();
11+
if (path_is_absolute($path)) {
12+
assertType('non-falsy-string', $path);
13+
}
14+
if (! path_is_absolute($path)) {
15+
assertType('string', $path);
16+
}
17+
18+
$path = Faker::nonFalsyString();
19+
if (path_is_absolute($path)) {
20+
assertType('non-falsy-string', $path);
21+
}
22+
if (! path_is_absolute($path)) {
23+
assertType('non-falsy-string', $path);
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpStubs\WordPress\Core\Tests;
6+
7+
use function path_is_absolute;
8+
use function PHPStan\Testing\assertType;
9+
10+
assertType('false', path_is_absolute(''));
11+
assertType('false', path_is_absolute('0'));
12+
assertType('bool', path_is_absolute('foo'));
13+
assertType('bool', path_is_absolute(Faker::string()));

wordpress-stubs.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130055,6 +130055,8 @@ function wp_mkdir_p($target)
130055130055
*
130056130056
* @param string $path File path.
130057130057
* @return bool True if path is absolute, false is not absolute.
130058+
* @phpstan-assert-if-true =non-falsy-string $path
130059+
* @phpstan-return ($path is non-falsy-string ? bool : false)
130058130060
*/
130059130061
function path_is_absolute($path)
130060130062
{

0 commit comments

Comments
 (0)