diff --git a/functionMap.php b/functionMap.php index a4ca9aa..dabc7cb 100644 --- a/functionMap.php +++ b/functionMap.php @@ -38,6 +38,7 @@ 'addslashes_gpc' => ['T', '@phpstan-template' => 'T', 'gpc' => 'T'], 'add_submenu_page' => [null, 'callback' => "''|callable"], 'have_posts' => [null, '@phpstan-impure' => ''], + 'paginate_links' => ["(\$args is array{total: int} ? void : (\$args is array{type: 'array'} ? list : string))"], 'rawurlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], 'sanitize_category' => ['T', '@phpstan-template' => 'T of array|object', 'category' => 'T'], 'sanitize_post' => ['T', '@phpstan-template' => 'T of array|object', 'post' => 'T'], diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 8a2c580..9c04aa0 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -38,6 +38,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/has_filter.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/is_wp_error.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/mysql2date.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/paginate_links.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'); diff --git a/tests/data/paginate_links.php b/tests/data/paginate_links.php new file mode 100644 index 0000000..50c1153 --- /dev/null +++ b/tests/data/paginate_links.php @@ -0,0 +1,35 @@ + $negInt, 'key' => 'value'])); +assertType('null', paginate_links(['total' => 0, 'key' => 'value'])); +assertType('null', paginate_links(['total' => 1, 'key' => 'value'])); + +// Returns list +assertType('list', paginate_links(['type' => 'array', 'key' => 'value'])); + +// Returns string +assertType('string', paginate_links(['type' => 'plain', 'key' => 'value'])); +assertType('string', paginate_links(['type' => 'list', 'key' => 'value'])); +assertType('string', paginate_links(['type' => 'thing', 'key' => 'value'])); + +// Returns string by default +assertType('string', paginate_links(['key' => 'value'])); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 8ecab90..22b9a64 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -112774,6 +112774,7 @@ function language_attributes($doctype = 'html') * before_page_number?: string, * after_page_number?: string, * } $args + * @phpstan-return ($args is array{total: int} ? void : ($args is array{type: 'array'} ? list : string)) */ function paginate_links($args = '') {