Skip to content

Commit

Permalink
Add __get and __call for WP_Query (#220)
Browse files Browse the repository at this point in the history
* Add __get and __call for WP_Query

* Fix wp_query test

* Add note about void->null conversion

* Fix cs

* Fix cs
  • Loading branch information
IanDelMar authored Sep 10, 2024
1 parent 98a5a30 commit 90de094
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,5 @@
'size_format' => ["(\$bytes is not numeric ? false : (\$bytes is negative-int|'0' ? false : string))"],
'WP_Translations::translate' => ['($singular is null ? null : string)'],
'WP_Translations::translate_plural' => ['($singular is null ? null : ($plural is null ? T : string))', '@phpstan-template T' => 'of string|null', 'singular' => 'T', 'count' => 'int'],
'WP_Query' => [null, '@phpstan-property-read bool $query_vars_changed' => '', '@phpstan-property-read bool|string $query_vars_hash' => '', '@phpstan-method void init_query_flags()' => ''],
];
1 change: 1 addition & 0 deletions tests/TypeInferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_categories.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_pages.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_parse_list.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_query.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_rest_request.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_tag_cloud.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php');
Expand Down
23 changes: 23 additions & 0 deletions tests/data/wp_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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 WP_Query;

use function PHPStan\Testing\assertType;

$wpQuery = new WP_Query();

assertType('bool', $wpQuery->query_vars_changed);
assertType('bool|string', $wpQuery->query_vars_hash);
assertType('null', $wpQuery->init_query_flags());
3 changes: 3 additions & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -46297,6 +46297,9 @@ public function to_array()
*
* @since 1.5.0
* @since 4.5.0 Removed the `$comments_popup` property.
* @phpstan-property-read bool $query_vars_changed
* @phpstan-property-read bool|string $query_vars_hash
* @phpstan-method void init_query_flags()
*/
#[\AllowDynamicProperties]
class WP_Query
Expand Down

0 comments on commit 90de094

Please sign in to comment.