Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into wp_list_pages
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar committed Aug 24, 2024
2 parents 5bb26b1 + b538a39 commit 974cc96
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 2 additions & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
43 changes: 43 additions & 0 deletions tests/data/wp_dropdown_languages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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_dropdown_languages;
use function PHPStan\Testing\assertType;

/** @var ''|null $emptyStringOrNull */
$emptyStringOrNull = $_GET['nullOrEmptyString'];

/** @var string|null $stringOrNull */
$stringOrNull = $_GET['unknown'];

// Default value
assertType('string', wp_dropdown_languages());
assertType('string', wp_dropdown_languages(['selected' => '']));

// 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' => '']));
31 changes: 31 additions & 0 deletions tests/data/wp_get_archives.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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_get_archives;
use function PHPStan\Testing\assertType;

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

// Explicit value of true|1
assertType('null', wp_get_archives(['echo' => 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']));
2 changes: 2 additions & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '')
{
Expand Down Expand Up @@ -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())
{
Expand Down

0 comments on commit 974cc96

Please sign in to comment.