Repository navigation
Build/Test Tools: Check prepared SQL with PHPStan instead of PHPCS - #15856
Draft
johnbillion wants to merge 2 commits into
Draft
johnbillion wants to merge 2 commits into
johnbillion wants to merge 2 commits into
Conversation
Adds a PHPUnit suite for the custom PHPStan extensions in `tests/phpstan`, built on PHPStan's test harness. The suite runs with `composer phpstan:test` or `npm run typecheck:php:test`, and runs in CI ahead of the static analysis. See #66634.
Ports the `InterpolatedNotPrepared` check of the `WordPress.DB.PreparedSQL` sniff and the `UnfinishedPrepare` check of the `WordPress.DB.PreparedSQLPlaceholders` sniff to PHPStan rules, which report under the same codes. The rules recognize the database object by its type as well as by the name `$wpdb`, and a query passed by name. The two checks are disabled in `phpcs.xml.dist`, the `phpcs:ignore` comments written for them are removed, and the errors they covered are added to the PHPStan baselines.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports two
WordPress.DBsniff checks to PHPStan rules that report under the same codes:WordPress.DB.PreparedSQL.InterpolatedNotPreparedWordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepareThe rules work on the syntax tree, recognize the database object by type as well as by the name
$wpdb, and handle a query passed by name. The two checks are disabled inphpcs.xml.dist, thephpcs:ignorecomments written for them are removed, and the errors those comments covered move into the PHPStan baselines.Depends on #15850. This branch is stacked on it, so the first commit here is that PR's. Only the last commit belongs to this PR.
Trac ticket:
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Writing the rules and tests, and preparing this PR.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.