Skip to content

Commit

Permalink
Add cond. return type for wp_list_pages()
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar committed Aug 24, 2024
1 parent c0bd4b0 commit 5bb26b1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'WP_Http::head' => [$httpReturnType],
'WP_Http::post' => [$httpReturnType],
'WP_Http::request' => [$httpReturnType],
'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],
'WP_Query::have_posts' => [null, '@phpstan-impure' => ''],
Expand Down
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function dataFileAsserts(): iterable
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_error_parameter.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');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wpdb.php');
Expand Down
28 changes: 28 additions & 0 deletions tests/data/wp_list_pages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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_pages;
use function PHPStan\Testing\assertType;

// Default value of true
assertType('null', wp_list_pages());

// Explicit value of true
assertType('null', wp_list_pages(['echo' => true, 'key' => 'value']));

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

// Unknown value
assertType('string|null', wp_list_pages(['echo' => (bool)$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 @@ -132073,6 +132073,7 @@ function wp_dropdown_pages($args = '')
* post_type?: string,
* post_status?: string|array,
* } $args
* @phpstan-return ($args is array{echo: false} ? string : void)
*/
function wp_list_pages($args = '')
{
Expand Down

0 comments on commit 5bb26b1

Please sign in to comment.