Skip to content
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
4 changes: 2 additions & 2 deletions .harness.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"framework"
],
"ratchet": {
"type_coverage": 100,
"phpstan_level": 5,
"phpstan_level": 8,
"phpstan_baseline": 0,
"coverage": 97.12,
"type_coverage": 100,
"msi": 93
}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
includes:
- vendor/pollora/harness/presets/phpstan/base.neon
parameters:
level: 5
level: 8
paths:
- src
8 changes: 4 additions & 4 deletions src/DateQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function inclusive(): self
}

/**
* @return array<array|string>
* @return array<int|string, string|array<int|string, mixed>>
*/
public function get(): array
{
Expand All @@ -40,8 +40,8 @@ public function get(): array
}

/**
* @param array<array|string> $query
* @return array<array|string>
* @param array<int|string, string|array<int|string, mixed>> $query
* @return array<int|string, string|array<int|string, mixed>>
*/
private function applyInclusive(array $query): array
{
Expand All @@ -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<array|string> $clause
* @param array<int|string, mixed> $clause
*/
private function isClause(array $clause): bool
{
Expand Down
6 changes: 6 additions & 0 deletions src/PostQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class PostQuery
use Tag;
use TaxQuery;

/**
* @param array<int>|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)) {
Expand All @@ -69,6 +72,9 @@ public function __construct(array|int|null $postId = null, ?string $fields = nul
}
}

/**
* @param array<int>|int|null $postId
*/
public static function find(array|int|null $postId = null): self
{
return new static($postId);
Expand Down
2 changes: 1 addition & 1 deletion src/QueryBuilder/ComparisonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function withType(?string $type): self
}

/**
* @return array<string, string|int|array|null>
* @return array<string, mixed>
*/
public function buildConfig(): array
{
Expand Down
32 changes: 16 additions & 16 deletions src/QueryBuilder/DateQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ class DateQueryBuilder extends SubQuery
/**
* Always an array: every setter goes through extractFromDate(), which never returns a string.
*
* @var array<string, string|int|array>|null
* @var array<string, string|int|array<mixed>>|null
*/
private ?array $after = null;

/**
* Always an array: every setter goes through extractFromDate(), which never returns a string.
*
* @var array<string, string|int|array>|null
* @var array<string, string|int|array<mixed>>|null
*/
private ?array $before = null;

Expand Down Expand Up @@ -81,6 +81,8 @@ public function modified(): self
}

/**
* @param array<string, string|int|array<mixed>>|string $date
*
* @throws QueryException
*/
public function within(array|string $date, string $extract = 'YmdHis'): self
Expand All @@ -102,7 +104,8 @@ public function within(array|string $date, string $extract = 'YmdHis'): self
}

/**
* @param array<string, string|int|array>|string $toDate
* @param array<string, string|int|array<mixed>>|string $fromDate
* @param array<string, string|int|array<mixed>>|string $toDate
*
* @throws QueryException
*/
Expand All @@ -116,7 +119,7 @@ public function between(array|string $fromDate, array|string $toDate): self
}

/**
* @param array<string, string|int|array>|string $beforeDate
* @param array<string, string|int|array<mixed>>|string $beforeDate
*
* @throws QueryException
*/
Expand All @@ -128,7 +131,7 @@ public function before(array|string $beforeDate): self
}

/**
* @param array<string, string|int|array>|string $afterDate
* @param array<string, string|int|array<mixed>>|string $afterDate
*
* @throws QueryException
*/
Expand All @@ -140,8 +143,8 @@ public function after(array|string $afterDate): self
}

/**
* @param array<string, string|int|array>|string $date
* @return array<string, string|int|array>
* @param array<string, string|int|array<mixed>>|string $date
* @return array<string, string|int|array<mixed>>
*
* @throws QueryException
*/
Expand All @@ -161,7 +164,7 @@ public function extractFromDate(array|string $date, string $extract = 'YmdHis'):
}

/**
* @return array<string, string|int|array>
* @return array<string, mixed>
*/
public function get(): array
{
Expand All @@ -175,7 +178,7 @@ public function get(): array
}

/**
* @param array<string, string|int|array> $date
* @param array<string, string|int|array<mixed>> $date
*
* @throws QueryException
*/
Expand Down Expand Up @@ -218,7 +221,7 @@ private function extractDateDetails(int $date, string $extract): array
}

/**
* @return array<string, string|int|array>
* @return array<string, mixed>
*/
private function buildClause(): array
{
Expand All @@ -241,7 +244,7 @@ private function buildClause(): array
}

/**
* @return array<string, string|int|array>
* @return array<string, mixed>
*/
private function handleBeforeAndAfter(): array
{
Expand All @@ -253,10 +256,7 @@ private function handleBeforeAndAfter(): array
}

/**
* @return array{
* column: string|null,
* before: array<string, string|int|array>
* }
* @return array<string, mixed>
*/
private function handleBeforeOnly(): array
{
Expand All @@ -267,7 +267,7 @@ private function handleBeforeOnly(): array
}

/**
* @return array<string, string|int|array>
* @return array<string, mixed>
*/
private function handleAfterOnly(): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/QueryBuilder/MetaQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function notLike(string $value): self
}

/**
* @param array<array|int|string> $value
* @param array<array<mixed>|int|string> $value
* @return $this
*/
public function in(array $value): self
Expand All @@ -116,7 +116,7 @@ public function in(array $value): self
}

/**
* @param array<array|int|string> $value
* @param array<array<mixed>|int|string> $value
* @return $this
*/
public function notIn(array $value): self
Expand Down Expand Up @@ -189,7 +189,7 @@ public function state(string $state): self
}

/**
* @return array<string, string|int|array>
* @return array<string, mixed>
*/
public function get(): array
{
Expand Down
12 changes: 7 additions & 5 deletions src/QueryBuilder/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
class QueryBuilder
{
/**
* @var array<string|array>
* @var array<int|string, string|array<int|string, mixed>>
*/
protected array $query = ['relation' => 'AND'];

/**
* @var array<string|array>
* References to the level being filled, indexed by depth.
*
* @var array<int, array<int|string, mixed>>
*/
protected array $stack = [];

Expand Down Expand Up @@ -46,7 +48,7 @@ public function orWhere(Closure|SubQuery $callback): self
}

/**
* @return array<array|string>
* @return array<int|string, string|array<int|string, mixed>>
*/
public function get(): array
{
Expand Down Expand Up @@ -90,7 +92,7 @@ private function applyRelation(array &$current, string $relation): void
}

/**
* @param $current array<string, string|int|array>
* @param array<int|string, mixed> $current
*/
private function handleSubQuery(array &$current, SubQuery $subQueryInstance): void
{
Expand All @@ -107,7 +109,7 @@ private function handleSubQuery(array &$current, SubQuery $subQueryInstance): vo
}

/**
* @param $current array<string, string|int|array>
* @param array<int|string, mixed> $current
*/
private function handleCallback(array &$current, Closure $callback): void
{
Expand Down
8 changes: 8 additions & 0 deletions src/Traits/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@

trait Comment
{
/**
* A number of comments, or a `value` / `compare` pair.
*
* @var int|array<string, int|string>|null
*/
protected int|array|null $commentCount = null;

/**
* @param int|array<string, int|string> $count
*/
public function commentCount(int|array $count): self
{
$this->commentCount = $count;
Expand Down
3 changes: 3 additions & 0 deletions src/Traits/Comments/Retrieval.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ trait Retrieval
{
use RetrievesRecords;

/**
* @return WP_Comment_Query
*/
protected function newWpQuery(): object
{
return new WP_Comment_Query;
Expand Down
6 changes: 6 additions & 0 deletions src/Traits/Concerns/RetrievesRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Traits/DateQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait DateQuery
use SubQueryTrait;

/**
* @var array<string|array>
* @var array<int|string, mixed>|null
*/
protected ?array $dateQuery = null;

Expand Down
2 changes: 1 addition & 1 deletion src/Traits/MetaQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait MetaQuery
use SubQueryTrait;

/**
* @var array<string|array>
* @var array<int|string, mixed>|null
*/
protected ?array $metaQuery = null;

Expand Down
6 changes: 6 additions & 0 deletions src/Traits/MimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

trait MimeType
{
/**
* @var string|array<string>|null
*/
protected string|array|null $postMimeType = null;

/**
* @param string|array<string> $value
*/
public function postMimeType(string|array $value): self
{
$this->postMimeType = $value;
Expand Down
3 changes: 3 additions & 0 deletions src/Traits/Networks/Retrieval.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ trait Retrieval
{
use RetrievesRecords;

/**
* @return WP_Network_Query
*/
protected function newWpQuery(): object
{
return new WP_Network_Query;
Expand Down
6 changes: 6 additions & 0 deletions src/Traits/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

trait PostType
{
/**
* @var string|array<string>
*/
protected string|array $postType = 'any';

/**
* @param string|array<string> $postType
*/
public function postType(string|array $postType): self
{
$this->postType = $postType;
Expand Down
Loading
Loading