Skip to content

Commit

Permalink
add stubs for wp_get_archives (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar authored Aug 24, 2024
1 parent c0bd4b0 commit 9c910d8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'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
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_get_archives.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
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']));
1 change: 1 addition & 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

0 comments on commit 9c910d8

Please sign in to comment.