Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cond. return type for wp_list_pages() #200

Merged
merged 4 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'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],
'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 @@ -37,6 +37,7 @@ public function dataFileAsserts(): iterable
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');
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 @@ -132077,6 +132077,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