Skip to content

chore(phpstan): raise the analysis from level 5 to level 8 - #45

Merged
ogorzalka merged 4 commits into
mainfrom
chore/phpstan-level
Nov 26, 2026
Merged

ogorzalka merged 4 commits into
mainfrom
chore/phpstan-level

Conversation

@ogorzalka

Copy link
Copy Markdown
Member

Branch chore/phpstan-level, base main. One commit per level, each recorded with vendor/bin/pollora-qa ratchet --update (it also reorders the keys of .harness.json).

Changes

  • Level 6: PHPDoc only (value types of the clause arrays and of the array parameters).

  • Level 7: newWpQuery() implementations document the query class they return; PostQuery::ids() maps through a typed closure; the date builder's get() PHPDoc admits inclusive => true.

  • Level 8: the date builder's private shapes admit the nullable values; PostQuery::ids() tolerates a null posts.

  • Wider public return PHPDoc: ComparisonBuilder::buildConfig(), MetaQueryBuilder::get() and DateQueryBuilder::get() now say array<string, mixed>; the old types left out values the code returns (a meta value of any type, inclusive => true).

No native signature, no query argument changes.

Level 9 (not done): what it needs

33 errors remain at level 9. The blocker is a public contract:

  • Eight constructor calls (CommentQuery, NetworkQuery, SiteQuery, TermQuery, UserQuery::get(), Term\Retrieval, two in User\Retrieval; nine reports) pass array<string, mixed> to constructors the WordPress stubs type with array shapes. getArguments() is public, shared by BuildsArguments and built by pollora/wordpress-args: it would need a shape per query class (or typing in wordpress-args). An @var, an ignoreErrors or a baseline entry would only hide it.
  • Public PHPDoc that is not checked at runtime: first() returns what WordPress returns (mixed), TermQuery::names() / slugs() and UserQuery::pluck() declare array<string>.
  • Internal, fixable afterwards: the state key of a sub-query (mixed used as an array key, QueryBuilder and Traits\Query\SubQuery), the intval(...) callbacks of ids(), the DateQuery::applyInclusive() argument.

Checked

  • PHPStan level 8: no error, no baseline (phpstan 2.3.7, wordpress-args 2.0.0); also with --prefer-lowest (phpstan 2.3.2, wordpress-args 1.1.0, phpstan-wordpress 2.0.0), where the tests pass too.
  • composer qa:fast and composer qa pass (macOS, PHP 8.4); 442 tests, 1 incomplete.
  • check --coverage --mutation: coverage 97.8 %, MSI 93.45 % (floors 97.12 / 93, unchanged).
  • roave-backward-compatibility-check against main, run on the level-8 code before a last one-token change inside a method body: no break.

Not verified

  • The integration suite (real WordPress and database) and the framework (downstream) job were not run.
  • PHP 8.3.
  • Semgrep is not installed on this machine: the security-pattern gates did not run.

@ogorzalka
ogorzalka merged commit 9502d5c into main Nov 26, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant