From 5bb26b1d66e930e242c121aab3b80dc731361519 Mon Sep 17 00:00:00 2001 From: Marian <42134098+IanDelMar@users.noreply.github.com> Date: Sat, 24 Aug 2024 06:32:14 +0200 Subject: [PATCH] Add cond. return type for wp_list_pages() --- functionMap.php | 1 + tests/TypeInferenceTest.php | 1 + tests/data/wp_list_pages.php | 28 ++++++++++++++++++++++++++++ wordpress-stubs.php | 1 + 4 files changed, 31 insertions(+) create mode 100644 tests/data/wp_list_pages.php diff --git a/functionMap.php b/functionMap.php index a23ba03..7f2c32f 100644 --- a/functionMap.php +++ b/functionMap.php @@ -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' => ''], diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 7d7ffbd..8e413c3 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -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'); diff --git a/tests/data/wp_list_pages.php b/tests/data/wp_list_pages.php new file mode 100644 index 0000000..bd5095b --- /dev/null +++ b/tests/data/wp_list_pages.php @@ -0,0 +1,28 @@ + 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'])); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 1efeef2..949fe13 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -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 = '') {