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 974cc96 + 4ea697c commit 461083c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Generate stubs

on: workflow_dispatch

env:
php-version: '7.4'

jobs:
generate-stubs:
name: Generate stubs
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
ini-file: development
php-version: ${{ env.php-version }}

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Generate stubs
run: |
./generate.sh # Generate stubs
- name: Commit file
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "[email protected]"
git add wordpress-stubs.php
git commit -m "Update WordPress stubs" || exit 0
git push origin ${{ github.ref_name }}
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'WP_Http::head' => [$httpReturnType],
'WP_Http::post' => [$httpReturnType],
'WP_Http::request' => [$httpReturnType],
'wp_list_bookmarks' => ['($args is array{echo: false|0} ? string : void)'],
'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],
Expand Down
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function dataFileAsserts(): iterable
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_bookmarks.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
31 changes: 31 additions & 0 deletions tests/data/wp_list_bookmarks.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_list_bookmarks;
use function PHPStan\Testing\assertType;

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

// Explicit value of true|1
assertType('null', wp_list_bookmarks(['echo' => true, 'key' => 'value']));
assertType('null', wp_list_bookmarks(['echo' => 1, 'key' => 'value']));

// Explicit value of false|0
assertType('string', wp_list_bookmarks(['echo' => false, 'key' => 'value']));
assertType('string', wp_list_bookmarks(['echo' => 0, 'key' => 'value']));

// Unknown value
assertType('string|null', wp_list_bookmarks(['echo' => (bool)$GET['echo'], 'key' => 'value']));
assertType('string|null', wp_list_bookmarks(['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 @@ -100931,6 +100931,7 @@ function _walk_bookmarks($bookmarks, $args = '')
* category_orderby?: string,
* category_order?: string,
* } $args
* @phpstan-return ($args is array{echo: false|0} ? string : void)
*/
function wp_list_bookmarks($args = '')
{
Expand Down

0 comments on commit 461083c

Please sign in to comment.