Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __get and __call for WP_Query #220

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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