diff --git a/functionMap.php b/functionMap.php index 7f2c32f..384a6fa 100644 --- a/functionMap.php +++ b/functionMap.php @@ -42,9 +42,11 @@ 'stripslashes_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], 'urldecode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], 'urlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], + 'wp_dropdown_languages' => ["(\$args is array{id: null|''} ? void : (\$args is array{name: null|''} ? void : string))"], 'wp_clear_scheduled_hook' => ['(0|positive-int|($wp_error is false ? false : \WP_Error))', 'args' => $cronArgsType], 'wp_get_schedule' => [null, 'args' => $cronArgsType], 'wp_get_scheduled_event' => [null, 'args' => $cronArgsType], + 'wp_get_archives' => ['($args is array{echo: false|0} ? string : void)'], 'WP_Http::get' => [$httpReturnType], 'WP_Http::head' => [$httpReturnType], 'WP_Http::post' => [$httpReturnType], diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 8e413c3..68c9e2f 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -32,7 +32,9 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/mysql2date.php'); 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_dropdown_languages.php'); 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_pages.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_rest_request.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php'); diff --git a/tests/data/wp_dropdown_languages.php b/tests/data/wp_dropdown_languages.php new file mode 100644 index 0000000..38d452b --- /dev/null +++ b/tests/data/wp_dropdown_languages.php @@ -0,0 +1,43 @@ + ''])); + +// Void return type +assertType('null', wp_dropdown_languages(['id' => $emptyStringOrNull, 'selected' => ''])); +assertType('null', wp_dropdown_languages(['name' => $emptyStringOrNull, 'selected' => ''])); +assertType('null', wp_dropdown_languages(['id' => $emptyStringOrNull, 'name' => $emptyStringOrNull, 'selected' => ''])); + +// string return type +assertType('string', wp_dropdown_languages(['id' => 'nonEmptyString', 'selected' => ''])); +assertType('string', wp_dropdown_languages(['name' => 'nonEmptyString', 'selected' => ''])); +assertType('string', wp_dropdown_languages(['id' => 'nonEmptyString', 'name' => 'nonEmptyString', 'selected' => ''])); + +// Unknown value +assertType('string|null', wp_dropdown_languages(['id' => $stringOrNull, 'selected' => ''])); +assertType('string|null', wp_dropdown_languages(['name' => $stringOrNull, 'selected' => ''])); +assertType('string|null', wp_dropdown_languages(['id' => $stringOrNull, 'name' => $stringOrNull, 'selected' => ''])); +assertType('string|null', wp_dropdown_languages(['id' => 'nonEmptyString', 'name' => $stringOrNull, 'selected' => ''])); +assertType('string|null', wp_dropdown_languages(['id' => $stringOrNull, 'name' => 'nonEmptyString', 'selected' => ''])); diff --git a/tests/data/wp_get_archives.php b/tests/data/wp_get_archives.php new file mode 100644 index 0000000..544996d --- /dev/null +++ b/tests/data/wp_get_archives.php @@ -0,0 +1,31 @@ + true, 'key' => 'value'])); +assertType('null', wp_get_archives(['echo' => 1, 'key' => 'value'])); + +// Explicit value of false|0 +assertType('string', wp_get_archives(['echo' => false, 'key' => 'value'])); +assertType('string', wp_get_archives(['echo' => 0, 'key' => 'value'])); + +// Unknown value +assertType('string|null', wp_get_archives(['echo' => (bool)$GET['echo'], 'key' => 'value'])); +assertType('string|null', wp_get_archives(['echo' => (int)$GET['echo'], 'key' => 'value'])); diff --git a/wordpress-stubs.php b/wordpress-stubs.php index 949fe13..ae00d8d 100644 --- a/wordpress-stubs.php +++ b/wordpress-stubs.php @@ -117188,6 +117188,7 @@ function get_archives_link($url, $text, $format = 'html', $before = '', $after = * day?: string, * w?: string, * } $args + * @phpstan-return ($args is array{echo: false|0} ? string : void) */ function wp_get_archives($args = '') { @@ -120776,6 +120777,7 @@ function wp_get_l10n_php_file_data($php_file) * show_option_en_us?: bool, * explicit_option_en_us?: bool, * } $args + * @phpstan-return ($args is array{id: null|''} ? void : ($args is array{name: null|''} ? void : string)) */ function wp_dropdown_languages($args = array()) {