Skip to content

Commit

Permalink
Add cond. return type for size_format() (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar authored Aug 27, 2024
1 parent 53e74ab commit 7ba67b1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@
'WP_Widget::widget' => [null, 'instance' => 'T', 'args' => 'array{name:string,id:string,description:string,class:string,before_widget:string,after_widget:string,before_title:string,after_title:string,before_sidebar:string,after_sidebar:string,show_in_rest:boolean,widget_id:string,widget_name:string}'],
'wp_parse_list' => ['($input_list is array ? array<scalar> : list<string>)'],
'wp_parse_str' => [null, '@phpstan-param-out' => 'array<int|string, array|string> $result'],
'size_format' => ["(\$bytes is not numeric ? false : (\$bytes is negative-int|'0' ? false : string))"],
];
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/is_wp_error.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/mysql2date.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/rest_ensure_response.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/size_format.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/term_exists.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_debug_backtrace_summary.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_die.php');
Expand Down
15 changes: 15 additions & 0 deletions tests/data/size_format.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function PHPStan\Testing\assertType;
use function size_format;

assertType('string', size_format(123));
assertType('string', size_format('123'));
assertType('string', size_format('123.1'));
assertType('string', size_format(0));
assertType('false', size_format('0'));
assertType('false', size_format('string'));
1 change: 1 addition & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -112766,6 +112766,7 @@ function number_format_i18n($number, $decimals = 0)
* @param int|string $bytes Number of bytes. Note max integer size for integers.
* @param int $decimals Optional. Precision of number of decimal places. Default 0.
* @return string|false Number string on success, false on failure.
* @phpstan-return ($bytes is not numeric ? false : ($bytes is negative-int|'0' ? false : string))
*/
function size_format($bytes, $decimals = 0)
{
Expand Down

0 comments on commit 7ba67b1

Please sign in to comment.