Skip to content

Commit 90de094

Browse files
authored
Add __get and __call for WP_Query (#220)
* Add __get and __call for WP_Query * Fix wp_query test * Add note about void->null conversion * Fix cs * Fix cs
1 parent 98a5a30 commit 90de094

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

functionMap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,5 @@
192192
'size_format' => ["(\$bytes is not numeric ? false : (\$bytes is negative-int|'0' ? false : string))"],
193193
'WP_Translations::translate' => ['($singular is null ? null : string)'],
194194
'WP_Translations::translate_plural' => ['($singular is null ? null : ($plural is null ? T : string))', '@phpstan-template T' => 'of string|null', 'singular' => 'T', 'count' => 'int'],
195+
'WP_Query' => [null, '@phpstan-property-read bool $query_vars_changed' => '', '@phpstan-property-read bool|string $query_vars_hash' => '', '@phpstan-method void init_query_flags()' => ''],
195196
];

tests/TypeInferenceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function dataFileAsserts(): iterable
5555
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_categories.php');
5656
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_list_pages.php');
5757
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_parse_list.php');
58+
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_query.php');
5859
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_rest_request.php');
5960
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_tag_cloud.php');
6061
yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_theme.php');

tests/data/wp_query.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* Note:
5+
* Starting from PHPStan 1.10.49, void types, including void in unions, are
6+
* transformed into null.
7+
*
8+
* @link https://github.com/phpstan/phpstan-src/pull/2778
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace PhpStubs\WordPress\Core\Tests;
14+
15+
use WP_Query;
16+
17+
use function PHPStan\Testing\assertType;
18+
19+
$wpQuery = new WP_Query();
20+
21+
assertType('bool', $wpQuery->query_vars_changed);
22+
assertType('bool|string', $wpQuery->query_vars_hash);
23+
assertType('null', $wpQuery->init_query_flags());

wordpress-stubs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46297,6 +46297,9 @@ public function to_array()
4629746297
*
4629846298
* @since 1.5.0
4629946299
* @since 4.5.0 Removed the `$comments_popup` property.
46300+
* @phpstan-property-read bool $query_vars_changed
46301+
* @phpstan-property-read bool|string $query_vars_hash
46302+
* @phpstan-method void init_query_flags()
4630046303
*/
4630146304
#[\AllowDynamicProperties]
4630246305
class WP_Query

0 commit comments

Comments
 (0)