From c4bd7b54f57b5307285a0ab057ad11571e8c1a67 Mon Sep 17 00:00:00 2001 From: Pollora maintainer Date: Thu, 26 Nov 2026 09:49:49 +0100 Subject: [PATCH 1/4] chore(phpstan): raise the analysis to level 6 --- .harness.json | 4 ++-- phpstan.neon | 2 +- src/DateQuery.php | 8 +++---- src/PostQuery.php | 6 ++++++ src/QueryBuilder/ComparisonBuilder.php | 2 +- src/QueryBuilder/DateQueryBuilder.php | 29 ++++++++++++++------------ src/QueryBuilder/MetaQueryBuilder.php | 6 +++--- src/QueryBuilder/QueryBuilder.php | 12 ++++++----- src/Traits/Comment.php | 8 +++++++ src/Traits/DateQuery.php | 2 +- src/Traits/MetaQuery.php | 2 +- src/Traits/MimeType.php | 6 ++++++ src/Traits/PostType.php | 6 ++++++ src/Traits/Status.php | 6 ++++++ src/Traits/TaxQuery.php | 2 +- 15 files changed, 69 insertions(+), 32 deletions(-) diff --git a/.harness.json b/.harness.json index 5227f69..19a1dfc 100644 --- a/.harness.json +++ b/.harness.json @@ -5,10 +5,10 @@ "framework" ], "ratchet": { - "type_coverage": 100, - "phpstan_level": 5, + "phpstan_level": 6, "phpstan_baseline": 0, "coverage": 97.12, + "type_coverage": 100, "msi": 93 } } diff --git a/phpstan.neon b/phpstan.neon index e36f167..0441f27 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,6 @@ includes: - vendor/pollora/harness/presets/phpstan/base.neon parameters: - level: 5 + level: 6 paths: - src diff --git a/src/DateQuery.php b/src/DateQuery.php index 468815e..d084714 100644 --- a/src/DateQuery.php +++ b/src/DateQuery.php @@ -30,7 +30,7 @@ public function inclusive(): self } /** - * @return array + * @return array> */ public function get(): array { @@ -40,8 +40,8 @@ public function get(): array } /** - * @param array $query - * @return array + * @param array> $query + * @return array> */ private function applyInclusive(array $query): array { @@ -61,7 +61,7 @@ private function applyInclusive(array $query): array /** * A first-order clause holds time keys, as opposed to a group of clauses. * - * @param array $clause + * @param array $clause */ private function isClause(array $clause): bool { diff --git a/src/PostQuery.php b/src/PostQuery.php index 414f473..a071cf7 100644 --- a/src/PostQuery.php +++ b/src/PostQuery.php @@ -56,6 +56,9 @@ class PostQuery use Tag; use TaxQuery; + /** + * @param array|int|null $postId A post ID, or a list of post IDs. + */ public function __construct(array|int|null $postId = null, ?string $fields = null) { if (is_int($postId)) { @@ -69,6 +72,9 @@ public function __construct(array|int|null $postId = null, ?string $fields = nul } } + /** + * @param array|int|null $postId + */ public static function find(array|int|null $postId = null): self { return new static($postId); diff --git a/src/QueryBuilder/ComparisonBuilder.php b/src/QueryBuilder/ComparisonBuilder.php index f50b4ad..9fc6d30 100644 --- a/src/QueryBuilder/ComparisonBuilder.php +++ b/src/QueryBuilder/ComparisonBuilder.php @@ -29,7 +29,7 @@ public function withType(?string $type): self } /** - * @return array + * @return array */ public function buildConfig(): array { diff --git a/src/QueryBuilder/DateQueryBuilder.php b/src/QueryBuilder/DateQueryBuilder.php index ad2cc25..c4d4456 100644 --- a/src/QueryBuilder/DateQueryBuilder.php +++ b/src/QueryBuilder/DateQueryBuilder.php @@ -31,14 +31,14 @@ class DateQueryBuilder extends SubQuery /** * Always an array: every setter goes through extractFromDate(), which never returns a string. * - * @var array|null + * @var array>|null */ private ?array $after = null; /** * Always an array: every setter goes through extractFromDate(), which never returns a string. * - * @var array|null + * @var array>|null */ private ?array $before = null; @@ -81,6 +81,8 @@ public function modified(): self } /** + * @param array>|string $date + * * @throws QueryException */ public function within(array|string $date, string $extract = 'YmdHis'): self @@ -102,7 +104,8 @@ public function within(array|string $date, string $extract = 'YmdHis'): self } /** - * @param array|string $toDate + * @param array>|string $fromDate + * @param array>|string $toDate * * @throws QueryException */ @@ -116,7 +119,7 @@ public function between(array|string $fromDate, array|string $toDate): self } /** - * @param array|string $beforeDate + * @param array>|string $beforeDate * * @throws QueryException */ @@ -128,7 +131,7 @@ public function before(array|string $beforeDate): self } /** - * @param array|string $afterDate + * @param array>|string $afterDate * * @throws QueryException */ @@ -140,8 +143,8 @@ public function after(array|string $afterDate): self } /** - * @param array|string $date - * @return array + * @param array>|string $date + * @return array> * * @throws QueryException */ @@ -161,7 +164,7 @@ public function extractFromDate(array|string $date, string $extract = 'YmdHis'): } /** - * @return array + * @return array> */ public function get(): array { @@ -175,7 +178,7 @@ public function get(): array } /** - * @param array $date + * @param array> $date * * @throws QueryException */ @@ -218,7 +221,7 @@ private function extractDateDetails(int $date, string $extract): array } /** - * @return array + * @return array> */ private function buildClause(): array { @@ -241,7 +244,7 @@ private function buildClause(): array } /** - * @return array + * @return array> */ private function handleBeforeAndAfter(): array { @@ -255,7 +258,7 @@ private function handleBeforeAndAfter(): array /** * @return array{ * column: string|null, - * before: array + * before: array> * } */ private function handleBeforeOnly(): array @@ -267,7 +270,7 @@ private function handleBeforeOnly(): array } /** - * @return array + * @return array> */ private function handleAfterOnly(): array { diff --git a/src/QueryBuilder/MetaQueryBuilder.php b/src/QueryBuilder/MetaQueryBuilder.php index 0e13487..72b1701 100644 --- a/src/QueryBuilder/MetaQueryBuilder.php +++ b/src/QueryBuilder/MetaQueryBuilder.php @@ -105,7 +105,7 @@ public function notLike(string $value): self } /** - * @param array $value + * @param array|int|string> $value * @return $this */ public function in(array $value): self @@ -116,7 +116,7 @@ public function in(array $value): self } /** - * @param array $value + * @param array|int|string> $value * @return $this */ public function notIn(array $value): self @@ -189,7 +189,7 @@ public function state(string $state): self } /** - * @return array + * @return array */ public function get(): array { diff --git a/src/QueryBuilder/QueryBuilder.php b/src/QueryBuilder/QueryBuilder.php index 76179ca..b94a02d 100644 --- a/src/QueryBuilder/QueryBuilder.php +++ b/src/QueryBuilder/QueryBuilder.php @@ -9,12 +9,14 @@ class QueryBuilder { /** - * @var array + * @var array> */ protected array $query = ['relation' => 'AND']; /** - * @var array + * References to the level being filled, indexed by depth. + * + * @var array> */ protected array $stack = []; @@ -46,7 +48,7 @@ public function orWhere(Closure|SubQuery $callback): self } /** - * @return array + * @return array> */ public function get(): array { @@ -90,7 +92,7 @@ private function applyRelation(array &$current, string $relation): void } /** - * @param $current array + * @param array $current */ private function handleSubQuery(array &$current, SubQuery $subQueryInstance): void { @@ -107,7 +109,7 @@ private function handleSubQuery(array &$current, SubQuery $subQueryInstance): vo } /** - * @param $current array + * @param array $current */ private function handleCallback(array &$current, Closure $callback): void { diff --git a/src/Traits/Comment.php b/src/Traits/Comment.php index 95a670f..296575f 100644 --- a/src/Traits/Comment.php +++ b/src/Traits/Comment.php @@ -6,8 +6,16 @@ trait Comment { + /** + * A number of comments, or a `value` / `compare` pair. + * + * @var int|array|null + */ protected int|array|null $commentCount = null; + /** + * @param int|array $count + */ public function commentCount(int|array $count): self { $this->commentCount = $count; diff --git a/src/Traits/DateQuery.php b/src/Traits/DateQuery.php index 2a64b40..cef5f24 100644 --- a/src/Traits/DateQuery.php +++ b/src/Traits/DateQuery.php @@ -12,7 +12,7 @@ trait DateQuery use SubQueryTrait; /** - * @var array + * @var array|null */ protected ?array $dateQuery = null; diff --git a/src/Traits/MetaQuery.php b/src/Traits/MetaQuery.php index 14afe3c..0f6be09 100644 --- a/src/Traits/MetaQuery.php +++ b/src/Traits/MetaQuery.php @@ -12,7 +12,7 @@ trait MetaQuery use SubQueryTrait; /** - * @var array + * @var array|null */ protected ?array $metaQuery = null; diff --git a/src/Traits/MimeType.php b/src/Traits/MimeType.php index a09f5c8..8cdba4c 100644 --- a/src/Traits/MimeType.php +++ b/src/Traits/MimeType.php @@ -6,8 +6,14 @@ trait MimeType { + /** + * @var string|array|null + */ protected string|array|null $postMimeType = null; + /** + * @param string|array $value + */ public function postMimeType(string|array $value): self { $this->postMimeType = $value; diff --git a/src/Traits/PostType.php b/src/Traits/PostType.php index b40d622..8a3a9a1 100644 --- a/src/Traits/PostType.php +++ b/src/Traits/PostType.php @@ -6,8 +6,14 @@ trait PostType { + /** + * @var string|array + */ protected string|array $postType = 'any'; + /** + * @param string|array $postType + */ public function postType(string|array $postType): self { $this->postType = $postType; diff --git a/src/Traits/Status.php b/src/Traits/Status.php index 13b2988..511da90 100644 --- a/src/Traits/Status.php +++ b/src/Traits/Status.php @@ -6,8 +6,14 @@ trait Status { + /** + * @var string|array|null + */ protected string|array|null $postStatus = null; + /** + * @param string|array $status + */ public function postStatus(string|array $status): self { $this->postStatus = $status; diff --git a/src/Traits/TaxQuery.php b/src/Traits/TaxQuery.php index 8b1276f..aa96654 100644 --- a/src/Traits/TaxQuery.php +++ b/src/Traits/TaxQuery.php @@ -12,7 +12,7 @@ trait TaxQuery use SubQueryTrait; /** - * @var array + * @var array|null */ protected ?array $taxQuery = null; From ad05b067ef50f1a96998e28794524a5e91a3577a Mon Sep 17 00:00:00 2001 From: Pollora maintainer Date: Thu, 26 Nov 2026 09:54:37 +0100 Subject: [PATCH 2/4] chore(phpstan): raise the analysis to level 7 --- .harness.json | 2 +- phpstan.neon | 2 +- src/QueryBuilder/DateQueryBuilder.php | 2 +- src/Traits/Comments/Retrieval.php | 3 +++ src/Traits/Concerns/RetrievesRecords.php | 6 ++++++ src/Traits/Networks/Retrieval.php | 3 +++ src/Traits/Retrieval.php | 3 ++- src/Traits/Sites/Retrieval.php | 3 +++ 8 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.harness.json b/.harness.json index 19a1dfc..376b88b 100644 --- a/.harness.json +++ b/.harness.json @@ -5,7 +5,7 @@ "framework" ], "ratchet": { - "phpstan_level": 6, + "phpstan_level": 7, "phpstan_baseline": 0, "coverage": 97.12, "type_coverage": 100, diff --git a/phpstan.neon b/phpstan.neon index 0441f27..727fd69 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,6 @@ includes: - vendor/pollora/harness/presets/phpstan/base.neon parameters: - level: 6 + level: 7 paths: - src diff --git a/src/QueryBuilder/DateQueryBuilder.php b/src/QueryBuilder/DateQueryBuilder.php index c4d4456..6b34c7d 100644 --- a/src/QueryBuilder/DateQueryBuilder.php +++ b/src/QueryBuilder/DateQueryBuilder.php @@ -164,7 +164,7 @@ public function extractFromDate(array|string $date, string $extract = 'YmdHis'): } /** - * @return array> + * @return array */ public function get(): array { diff --git a/src/Traits/Comments/Retrieval.php b/src/Traits/Comments/Retrieval.php index af1dd1f..005613a 100644 --- a/src/Traits/Comments/Retrieval.php +++ b/src/Traits/Comments/Retrieval.php @@ -11,6 +11,9 @@ trait Retrieval { use RetrievesRecords; + /** + * @return WP_Comment_Query + */ protected function newWpQuery(): object { return new WP_Comment_Query; diff --git a/src/Traits/Concerns/RetrievesRecords.php b/src/Traits/Concerns/RetrievesRecords.php index f5f1d03..c60adf8 100644 --- a/src/Traits/Concerns/RetrievesRecords.php +++ b/src/Traits/Concerns/RetrievesRecords.php @@ -4,6 +4,10 @@ namespace Pollora\Query\Traits\Concerns; +use WP_Comment_Query; +use WP_Network_Query; +use WP_Site_Query; + /** * Terminal methods for the queries whose `query()` returns a list, or a number when `count` is set * (WP_Comment_Query, WP_Site_Query, WP_Network_Query). @@ -68,6 +72,8 @@ public function exists(): bool /** * A fresh WP_*_Query object, whose `query(array $args)` method is called with the arguments. + * + * @return WP_Comment_Query|WP_Network_Query|WP_Site_Query */ abstract protected function newWpQuery(): object; diff --git a/src/Traits/Networks/Retrieval.php b/src/Traits/Networks/Retrieval.php index e027745..618752c 100644 --- a/src/Traits/Networks/Retrieval.php +++ b/src/Traits/Networks/Retrieval.php @@ -11,6 +11,9 @@ trait Retrieval { use RetrievesRecords; + /** + * @return WP_Network_Query + */ protected function newWpQuery(): object { return new WP_Network_Query; diff --git a/src/Traits/Retrieval.php b/src/Traits/Retrieval.php index 726cba3..0381889 100644 --- a/src/Traits/Retrieval.php +++ b/src/Traits/Retrieval.php @@ -5,6 +5,7 @@ namespace Pollora\Query\Traits; use Pollora\Query\Traits\Concerns\CopiesBuilder; +use WP_Post; use WP_Query; /** @@ -45,7 +46,7 @@ public function ids(): array $copy->noFoundRows = true; }); - return array_map(intval(...), $query->posts); + return array_map(static fn (int|string|WP_Post $post): int => $post instanceof WP_Post ? $post->ID : (int) $post, $query->posts); } /** diff --git a/src/Traits/Sites/Retrieval.php b/src/Traits/Sites/Retrieval.php index 41e5277..7936398 100644 --- a/src/Traits/Sites/Retrieval.php +++ b/src/Traits/Sites/Retrieval.php @@ -11,6 +11,9 @@ trait Retrieval { use RetrievesRecords; + /** + * @return WP_Site_Query + */ protected function newWpQuery(): object { return new WP_Site_Query; From dc93a3889fb7f0467cdc6f5f057d47a7c95cfa72 Mon Sep 17 00:00:00 2001 From: Pollora maintainer Date: Thu, 26 Nov 2026 09:54:50 +0100 Subject: [PATCH 3/4] chore(phpstan): raise the analysis to level 8 --- .harness.json | 2 +- phpstan.neon | 2 +- src/QueryBuilder/DateQueryBuilder.php | 11 ++++------- src/Traits/Retrieval.php | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.harness.json b/.harness.json index 376b88b..c9b8e95 100644 --- a/.harness.json +++ b/.harness.json @@ -5,7 +5,7 @@ "framework" ], "ratchet": { - "phpstan_level": 7, + "phpstan_level": 8, "phpstan_baseline": 0, "coverage": 97.12, "type_coverage": 100, diff --git a/phpstan.neon b/phpstan.neon index 727fd69..6a6a148 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,6 @@ includes: - vendor/pollora/harness/presets/phpstan/base.neon parameters: - level: 7 + level: 8 paths: - src diff --git a/src/QueryBuilder/DateQueryBuilder.php b/src/QueryBuilder/DateQueryBuilder.php index 6b34c7d..71eac46 100644 --- a/src/QueryBuilder/DateQueryBuilder.php +++ b/src/QueryBuilder/DateQueryBuilder.php @@ -221,7 +221,7 @@ private function extractDateDetails(int $date, string $extract): array } /** - * @return array> + * @return array */ private function buildClause(): array { @@ -244,7 +244,7 @@ private function buildClause(): array } /** - * @return array> + * @return array */ private function handleBeforeAndAfter(): array { @@ -256,10 +256,7 @@ private function handleBeforeAndAfter(): array } /** - * @return array{ - * column: string|null, - * before: array> - * } + * @return array */ private function handleBeforeOnly(): array { @@ -270,7 +267,7 @@ private function handleBeforeOnly(): array } /** - * @return array> + * @return array */ private function handleAfterOnly(): array { diff --git a/src/Traits/Retrieval.php b/src/Traits/Retrieval.php index 0381889..9b51ce5 100644 --- a/src/Traits/Retrieval.php +++ b/src/Traits/Retrieval.php @@ -46,7 +46,7 @@ public function ids(): array $copy->noFoundRows = true; }); - return array_map(static fn (int|string|WP_Post $post): int => $post instanceof WP_Post ? $post->ID : (int) $post, $query->posts); + return array_map(static fn (int|string|WP_Post $post): int => $post instanceof WP_Post ? $post->ID : (int) $post, $query->posts ?: []); } /** From 8372b986a546467e9808875e51c5f281e2375d8c Mon Sep 17 00:00:00 2001 From: Pollora maintainer Date: Thu, 26 Nov 2026 10:00:39 +0100 Subject: [PATCH 4/4] docs: changelog for the PHPStan level --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ed48c1..e05e986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ Earlier releases (1.0 to 1.0.3) are listed on the [releases page](https://github ## [Unreleased] +### Changed + +- PHPStan runs at level 8 (was 5). The PHPDoc types of the builders now say what they hold and accept (clause arrays, `commentCount()`, `postType()`, `postStatus()`, `postMimeType()`, the date builder). No query changed. + ## [3.1.1] - 2026-11-23 ### Fixed