Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into wp_list_pages
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar committed Aug 24, 2024
2 parents 461083c + 794ff8a commit b62a9ae
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'WP_Http::post' => [$httpReturnType],
'WP_Http::request' => [$httpReturnType],
'wp_list_bookmarks' => ['($args is array{echo: false|0} ? string : void)'],
'wp_list_categories' => ['($args is array{echo: false|0} ? string|false : false|void)'],
'wp_list_pages' => ['($args is array{echo: false} ? string : void)'],
'WP_List_Table::set_pagination_args' => ['void', 'args' => 'array{total_items?: int, total_pages?: int, per_page?: int}'],
'wp_next_scheduled' => [null, 'args' => $cronArgsType],
Expand Down
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_error_parameter.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_get_archives.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_bookmarks.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_categories.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_pages.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_rest_request.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php');
Expand Down
31 changes: 31 additions & 0 deletions tests/data/wp_list_categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* Note:
* Starting from PHPStan 1.10.49, void types, including void in unions, are
* transformed into null.
*
* @link https://github.com/phpstan/phpstan-src/pull/2778
*/

declare(strict_types=1);

namespace PhpStubs\WordPress\Core\Tests;

use function wp_list_categories;
use function PHPStan\Testing\assertType;

// Default value of 1
assertType('false|null', wp_list_categories());

// Explicit value of true|1
assertType('false|null', wp_list_categories(['echo' => true, 'key' => 'value']));
assertType('false|null', wp_list_categories(['echo' => 1, 'key' => 'value']));

// Explicit value of false|0
assertType('string|false', wp_list_categories(['echo' => false, 'key' => 'value']));
assertType('string|false', wp_list_categories(['echo' => 0, 'key' => 'value']));

// Unknown value
assertType('string|false|null', wp_list_categories(['echo' => (bool)$GET['echo'], 'key' => 'value']));
assertType('string|false|null', wp_list_categories(['echo' => (int)$GET['echo'], 'key' => 'value']));
1 change: 1 addition & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -102127,6 +102127,7 @@ function wp_dropdown_categories($args = '')
* walker?: Walker,
* taxonomy?: string,
* } $args
* @phpstan-return ($args is array{echo: false|0} ? string|false : false|void)
*/
function wp_list_categories($args = '')
{
Expand Down

0 comments on commit b62a9ae

Please sign in to comment.