Repository navigation
Build/Test Tools: Hold selected paths to PHPStan rule level 10 - #16021
westonruter wants to merge 30 commits into
Conversation
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. |
bd03d72 to
9185bcf
Compare
…uration. Prepares the baseline generator for a second configuration, `phpstan-level-10.neon.dist`, which holds selected paths to rule level 10 and keeps its own baselines in `tests/phpstan/baselines-level-10`. Without `--config` or `--output-dir`, `composer phpstan:baselines` now processes each default configuration in turn, by running itself once per configuration, so that each pass is the same as one asked for directly. `phpstan.neon.dist` goes first, because the stricter configuration includes it along with its baselines, so its own are only what is left once those are up to date. `--identifier` and `--prune` apply to every pass. `--combined` prints a single baseline, so it still analyzes only `phpstan.neon.dist` unless `--config` names another configuration. Naming a default configuration without `--output-dir` writes to that configuration's own directory, so its baselines cannot land in the other's. A configuration that turns off `reportUnmatchedIgnoredErrors` would also stop reporting its own baseline entries once they go stale. When it is off, each generated entry sets `reportUnmatched: true`, which PHPStan lets override the global setting per entry. The setting is read from `phpstan dump-parameters`, matching only its line: the JSON that command prints can be invalid, since it writes the `\<` in a message pattern unescaped. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
`phpstan.neon.dist` analyzes the whole codebase at rule level 5. Much of the code added in recent releases, such as the Secrets API, the AI client and connectors, the Abilities API, and the style engine, already meets level 10 or nearly does, but nothing keeps it there. Add `phpstan-level-10.neon.dist`, which includes `phpstan.neon.dist` and reports level-10 errors only in the paths listed in its `strictPaths` parameter. PHPStan has no per-path rule level, and narrowing the analyzed paths would change what the analysis sees: the parser node visitors in `tests/phpstan`, such as `HashNotationVisitor`, only rewrite the docblocks of files that are analyzed, and PHPStan reads every other file with a parser that runs none of them. So the configuration analyzes every path `phpstan.neon.dist` does, and the new `StrictPathsIgnoreErrorExtension` drops each error outside the strict paths. A strict path that does not exist is an error, so a renamed file cannot quietly stop being checked. Errors already baselined by `phpstan.neon.dist` stay baselined there. The new `tests/phpstan/baselines-level-10` holds only the 30 errors level 10 adds in the strict paths. Those errors are dropped before ignores are matched against them, so every ignore outside the strict paths would be reported as unmatched; `reportUnmatchedIgnoredErrors` is therefore off, and each level-10 baseline entry turns it back on for itself, so a stale entry is still reported and fixable with `--fix`. The configuration keeps its own result cache, since PHPStan discards a result cache written at another rule level, while still sharing the reflection cache in `tmpDir`. The initial strict paths were chosen by analyzing all of core at level 10: of 27,859 errors in 1,427 files, the paths listed have at most a handful, most of them missing iterable value types or `mixed` values that are left for follow-up changes to fix. A local `phpstan-level-10.neon` can override the configuration, like `phpstan.neon` does. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
Core is now analyzed with two configurations: `phpstan.neon.dist` for the whole codebase, and `phpstan-level-10.neon.dist` for the paths held to rule level 10. A Composer script listing both would stop after the first, since PHPStan exits with a failure status whenever it reports an error, so the new `tests/phpstan/analyse.php` runs each in turn, passes its arguments to both, and exits with the highest status. Each analysis honors a local override the way PHPStan does: `phpstan.neon` for the first, which PHPStan finds by itself, and `phpstan-level-10.neon` for the second, which the script chooses. When a local `phpstan.neon` already analyzes everything at level 10, the second analysis is skipped, since it could only repeat part of the first. Naming a configuration with `--configuration` runs only that one. `composer phpstan:fix` now goes through the same script, which runs `--fix` with each `.dist` configuration, prunes both sets of baselines, and analyzes again. Since PHPStan exits with the same status when there is nothing to fix as when it fixed something, nothing to fix in one configuration no longer stops the fix of the other. The new `phpstan:level-5` and `phpstan:level-10` scripts each run one `.dist` configuration, for CI, which needs one report per run. `composer phpstan` no longer times out after Composer's default 300 seconds, since a cold run of both analyses can take longer. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
The PHPStan job becomes a matrix of two parallel jobs: one analyzing the whole codebase with `phpstan.neon.dist`, and one analyzing the paths held to rule level 10 with `phpstan-level-10.neon.dist`. Each caches separately, since a result cache written at one rule level is discarded by a run at another, and each annotates, uploads, and fails on errors that cannot be ignored on its own. Annotations from the level 10 analysis are titled `PHPStan (level 10)`, and the summary of out-of-date baselines names the analysis and links to its baselines and configuration. The artifact of the analysis of the whole codebase keeps its name, `phpstan-results`, and now lists the analyses the run makes. The level 10 analysis uploads `phpstan-results-level-10`. The PHPStan Pull Request Comments workflow downloads both and combines them into the one comment. Since the level 10 analysis includes everything the other one checks, an error reported by both is listed once, as found by the analysis of the whole codebase. A table listing an error found only by the level 10 analysis gains a Level column, and the comment then points to the documentation of the strict paths. The key identifying an error from one run to the next is unchanged, so the history kept in existing comments still applies. When the run lists the level 10 analysis but its results are missing, the comment is left as it is, rather than showing every error only that analysis reported as resolved. A run from a branch that does not have the second analysis yet lists none, and is reported as before. The name of the job changes to `Run PHP static analysis (all paths)` and `Run PHP static analysis (level 10 paths)`, which matters to any branch protection rule requiring the old name. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
The level 10 analysis analyzed every path and dropped the errors outside its strict paths, on the premise that narrowing the analyzed paths would read the rest of core without the WordPress-specific parser node visitors. That premise was wrong: `tests/phpstan/base.neon` redefines PHPStan's simple parser to wrap the rich one, so a file that is only scanned gets the same docblock rewriting as one that is analyzed. `phpstan-level-10.neon.dist` therefore now replaces the analyzed paths with the strict ones using `paths!`, and scans `src/wp-admin`, `src/wp-includes`, and the files in the root of `src` so that what they use is known. It reports exactly the same 30 errors, in about 3 seconds rather than a second analysis of the whole codebase. Since PHPStan 2.3.6 only reports an ignore as unmatched when what it ignores is within the analysis, the baselines and ignored errors of `phpstan.neon.dist` for files outside the strict paths are not reported, and `reportUnmatchedIgnoredErrors` can stay on. That makes the workarounds for dropping errors before ignores are matched unnecessary: `StrictPathsIgnoreErrorExtension` is removed, along with the generator's `reportUnmatched: true` on each level 10 baseline entry and the reading of `phpstan dump-parameters` it needed. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
Adds a section on the stricter analysis of selected paths to the PHPStan README: what `phpstan-level-10.neon.dist` holds to level 10 and why it can analyze only those paths, how its baselines layer on those of `phpstan.neon.dist`, how to add a path, and its local override. It also advises against an `@phpstan-ignore` comment in a strict path for an error only levels 6 to 10 report, which the analysis of the whole codebase would report as ignoring nothing, and which `composer phpstan:fix` would then remove. The sections on running the analysis, the results on pull requests, `composer phpstan:fix`, and regenerating the baselines now describe both analyses, and the header of `phpstan.neon.dist` points to the stricter configuration. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…rguments. `composer phpstan` passed every argument to both analyses, but some only make sense for one. Paths replaced the strict paths of the level 10 analysis, so `composer phpstan -- src/wp-includes/template.php`, as the README suggests, held that file to level 10 and failed. `--error-format=json` printed two reports in a row, which is not valid JSON; `--level` analyzed the strict paths at another level, leaving their baselines unmatched; and `--generate-baseline` wrote the same file twice. With paths, a configuration, a level, a report format, a baseline to generate, or `--fix-ignored`, only the first analysis now runs, as before there were two. An option's value given as the next argument is not taken for a path. The analyses also now run on the PHP that runs the script, which Composer's `@php` chose, rather than whichever `php` the shebang of `vendor/bin/phpstan` finds first. The script no longer uses `str_starts_with()`, which PHP 7.4 does not have. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…wn directory. Naming a local override such as `phpstan-level-10.neon`, which the README suggests, without `--output-dir` wrote its baselines to `tests/phpstan/baselines`. That is destructive: the level 10 analysis covers only the strict paths, so with the baselines there suppressed it reports few of their errors again, and every other baseline there would be retired. A configuration named as a default one but without the `.dist` suffix now writes to that configuration's directory, as naming the default one does. Any other configuration still writes to `tests/phpstan/baselines`, as `phpstan.neon` should. Accordingly, the command each baseline's header gives for regenerating it does not name `--output-dir` for such an override's own directory either. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…of the comment. When a table in the PHPStan pull request comment is cut short, it points to the “Report the analysis results” step of the workflow run for the rest. There is now one such step per analysis, and an error found only at level 10 is only in the log of the level 10 job, so the note says so when there is such an error. The list of analyses the results declare is also marked as needing to be kept in step with the job's matrix. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…trict path. The README now says which arguments make `composer phpstan` run only the first analysis, and that `composer phpstan:level-5` and `composer phpstan:level-10` always use the `.dist` configurations rather than a local override. Holding another path to level 10 now starts by making sure no baseline of `phpstan.neon.dist` has an entry for a file in it. The level 10 configuration includes those baselines, so both analyses enforce each entry's count, and if level 10 reports a different number of the errors one ignores, no count satisfies both, and `composer phpstan:fix` would change it back and forth between them. No strict path has such an entry today. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…vel 10. The Secrets API was reverted on trunk, so `src/wp-includes/secrets` and `src/wp-includes/secrets.php` no longer exist, and PHPStan refuses to run with a path that does not. They are removed from the strict paths, along with the three `argument.type` entries baselined for `class-wp-secrets-key-manager.php`. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
The README gave it as an example of code held to PHPStan level 10, which it no longer is, now that it has been reverted. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…ader. Since r65566, `phpstan.neon.dist` includes its baselines through `tests/phpstan/baselines/loader.php` rather than listing them between markers, and the generator no longer maintains such a list. `phpstan-level-10.neon.dist` now does the same with a loader of its own in `tests/phpstan/baselines-level-10`, which is the stub the generator writes for that directory. The level 10 baselines are regenerated for the new headers, which no longer mention an `includes` entry, and give `--config=phpstan-level-10.neon.dist` in the command that regenerates them. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
The generator wrote a directory's `loader.php` only after the analysis succeeded, but PHPStan refuses to run a configuration whose `includes` names a file that is missing. A configuration that already includes the loader of a directory not created yet, as `phpstan-level-10.neon.dist` does, could therefore not have its first baselines generated, nor could one whose loader had been deleted. The directory and its loader are now written before the analysis, which is unaffected, since the loader of the directory being regenerated includes nothing during it. `--combined` still writes nothing to disk. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
9185bcf to
d3bfc6b
Compare
Either rule level can be raised: that of `phpstan.neon.dist` as more of core complies, and that of the stricter configuration when PHPStan adds a level above 10, as it added 9 and 10 in its last two major versions. Names and checks built on 5 and 10 would each need to change along with it, so the two analyses are now named `default` and `strict`, and the levels are read from their configurations wherever they are needed: * `phpstan-level-10.neon.dist` becomes `phpstan-strict.neon.dist`, with its local override `phpstan-strict.neon`, and its baselines move to `tests/phpstan/baselines-strict`. * The Composer scripts `phpstan:level-5` and `phpstan:level-10` become `phpstan:default` and `phpstan:strict`, and so do the `analysis` values of the CI matrix, whose strict job artifact becomes `phpstan-results-strict`. * Each CI job reads the rule level of its configuration with `phpstan dump-parameters`, includes it in its annotation titles and in its results, and the pull request comment shows that level in its Level column rather than assuming 5 or 10. A level not reported, as by a branch from before this, is left blank. * `composer phpstan` skips the strict analysis when a local `phpstan.neon` is at the strict configuration's level or above, rather than at 10 or `max`. The strict configuration keeps setting `level: 10` rather than `max`, so that a PHPStan update adding a level does not raise it unannounced. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
`fs.readFileSync()` returns a string when given an encoding, but PhpStorm resolves the overload taking a bare encoding string to the one returning a `Buffer`, and warns that it is passed to `JSON.parse()`. The options object has the same effect and is resolved correctly. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
The header of each baseline ran its instruction to regenerate it into the command and on into the paragraph after, so a sentence was interrupted by a code block and resumed in lowercase. The instruction now ends at the command, and the paragraph after it is a sentence of its own. The baselines are regenerated for the new header. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…HPStan README. The paragraph opened with "It", which followed a sentence about the rule level and so could be read as referring to it, and "everything that enforces" left unclear which configuration was meant. Both are now named. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…an baseline. The header of a baseline gives the command that regenerates it, naming the configuration and output directory the run used where they are not the defaults. Those paths were written as given, so one containing a space, or anything else the shell splits or expands, would be passed as something else when the command was copied. They are now quoted for the shell, but only where needed, so the paths of the default configurations and their directories, and so the committed baselines, are written as before. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
An earlier edit left a short line in the middle of the paragraph about the environment variable naming the output directory. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…the PHPStan runner. `get_single_analysis_reason()` read its arguments by index, advancing the index within the loop to skip a value given as the argument after its option. PHPStan could not tell that each index read was below the count, and at level 10 reported `offsetAccess.notFound`. The arguments are now iterated directly, with a flag marking the next one as a value to skip, and documented as the list they always are. The result is the same for every argument list. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…level. The runner read the rule level from `phpstan dump-parameters` without checking its exit status, so whatever a failed run printed was searched for the level. A failure now leaves the level unknown, which is what not finding it already meant, and the strict analysis is then run rather than skipped. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…tan level. The runner and the CI job both find the rule level in the JSON that `phpstan dump-parameters` prints by matching its line, which required exactly one space after the key. PHPStan pretty-prints the JSON, which always puts one there, but JSON itself does not require it, so the pattern no longer does either. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…of its own. `run()` took a boolean saying whether the script was PHPStan, so that it would pass the `analyse` command first, and the one call running another script passed `false` with nothing at the call to say what it meant. `analyse()` now adds the command and runs PHPStan, and `run()` only runs a script with the arguments it is given. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…and. `analyse()` merged the command and the arguments into one array, which unpacking them into an array literal does more plainly. The arguments are always a list, which unpacking needs before PHP 8.1, so they are documented as one. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
| // The rule level the configuration analyzes at, as a number, or `max`. Only the line of the parameter is | ||
| // matched, rather than decoding the whole dump, because the JSON PHPStan prints can be invalid: it writes | ||
| // the `\<` in a message pattern as is, which is not a valid JSON escape. | ||
| let level = null; | ||
| try { | ||
| const parameters = require( 'child_process' ).execFileSync( | ||
| `${ process.env.GITHUB_WORKSPACE }/vendor/bin/phpstan`, | ||
| [ 'dump-parameters', `--configuration=${ process.env.CONFIG }`, '--json' ], | ||
| { encoding: 'utf8' } | ||
| ); | ||
| const match = parameters.match( /^\s*"level":\s*"?(max|\d+)"?,?$/m ); | ||
| if ( match ) { | ||
| level = match[ 1 ] === 'max' ? 'max' : Number( match[ 1 ] ); | ||
| } |
There was a problem hiding this comment.
🤖 Comment by Claude Opus 5.5 (medium effort)
The rule level is matched line by line here, and likewise in get_level() in tests/phpstan/analyse.php, only because phpstan dump-parameters --json prints invalid JSON. Once PHPStan encodes it correctly, and core requires a version that does, both places could decode the dump and read level directly.
Details
As of PHPStan 2.3.6, the dump of every configuration fails to parse, in both Node (Bad escaped character in JSON at position 16621) and PHP (json_decode(): Syntax error). The cause is the ignoreErrors message patterns from the baselines. preg_quote() escapes < and >, and while every other backslash in the dump is doubled, as JSON requires, the one before < or > is not:
"message": "#^Parameter \\#1 \\$key of function remove_query_arg expects array\<string\>\\|string, false given\\.$#",With that fixed upstream, this step could become:
const parameters = JSON.parse( require( 'child_process' ).execFileSync(
`${ process.env.GITHUB_WORKSPACE }/vendor/bin/phpstan`,
[ 'dump-parameters', `--configuration=${ process.env.CONFIG }`, '--json' ],
{ encoding: 'utf8' }
) );
level = Number.isSafeInteger( parameters.level ) || parameters.level === 'max' ? parameters.level : null;and get_level() would decode the output rather than search it:
$parameters = json_decode( implode( "\n", $output ), true );
$level = is_array( $parameters ) ? ( $parameters['level'] ?? null ) : null;
return is_int( $level ) || 'max' === $level ? (string) $level : null;That would also drop the assumptions the line match makes about the output's formatting, such as "level" being on a line of its own, and the comment above explaining the workaround.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
…ct configuration. The paths that trigger the static analysis on a pull request listed `phpstan.neon.dist` and its baselines, but not `phpstan-strict.neon.dist` or its baselines. A pull request adding a strict path, raising the strict level, or editing a strict baseline, and nothing else, was therefore never analyzed. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…lysis. `composer phpstan:default` and `composer phpstan:strict` were the only PHPStan scripts not to disable Composer's process timeout, so an analysis taking longer than its default of 300 seconds, as one on a cold cache can, was killed partway. CI runs each analysis through them, and would have reported from a truncated report. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
…g a PHPStan baseline. The header of a baseline of `phpstan.neon.dist` left the configuration out of its regenerate command, since it was the default. Without a configuration named, the generator now processes every default configuration, so that command also rewrote, or deleted, the baseline of the same identifier in `tests/phpstan/baselines-strict`, contrary to the header's saying it rewrites only that file. Every header now names the configuration, and the default baselines are regenerated for it. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
`composer phpstan` skips the strict analysis when the local `phpstan.neon` is at the strict level or above, and said the local configuration already analyzes every path. Only the levels are compared, though, so a local configuration narrowing its paths could leave strict paths unanalyzed. The message, the runner's description, and the README now say so, and point to `composer phpstan:strict` for that case. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
There was a problem hiding this comment.
🟡 Changes recommended
The comment workflow omits strict-only changes when determining whether line numbers may be stale, so findings from files changed on the base branch can link to incorrect lines in the PR.
1 open issue
What changed in this PR
Adds a second PHPStan analysis at rule level 10 for selected WordPress paths while preserving the existing project-wide level-5 analysis.
Changes:
- Adds strict configuration and dedicated baselines.
- Updates analysis, baseline-generation, Composer, and fix workflows.
- Extends CI reporting, pull-request comments, documentation, and local configuration handling.
| File | Description |
|---|---|
| tests/phpstan/README.md | Documents strict analysis, baseline maintenance, and updated commands. |
| tests/phpstan/generate-baselines.php | Generates and maintains baselines for the default and strict configurations. |
| tests/phpstan/baselines/varTag.noVariable.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/variable.undefined.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/return.type.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/property.private.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/property.notFound.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/property.nonObject.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/property.defaultValue.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/parameterByRef.unusedType.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/parameterByRef.type.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/offsetAssign.valueType.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/offsetAccess.notFound.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/notIdentical.alwaysTrue.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/method.unused.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/method.childParameterType.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/isset.property.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/if.alwaysTrue.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/if.alwaysFalse.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/identical.alwaysFalse.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/function.resultUnused.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/function.alreadyNarrowedType.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/empty.variable.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/empty.property.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/deadCode.unreachable.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/class.notFound.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/booleanNot.alwaysTrue.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/binaryOp.invalid.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/assign.propertyType.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/argument.unresolvableType.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines/argument.type.neon | Updates the default baseline regeneration metadata. |
| tests/phpstan/baselines-strict/return.type.neon | Adds strict-analysis baseline entries. |
| tests/phpstan/baselines-strict/offsetAccess.nonOffsetAccessible.neon | Adds strict-analysis baseline entries. |
| tests/phpstan/baselines-strict/missingType.return.neon | Adds strict-analysis baseline entries. |
| tests/phpstan/baselines-strict/missingType.iterableValue.neon | Adds strict-analysis baseline entries. |
| tests/phpstan/baselines-strict/method.notFound.neon | Adds strict-analysis baseline entries. |
| tests/phpstan/baselines-strict/loader.php | Loads strict baseline files dynamically. |
| tests/phpstan/baselines-strict/cast.int.neon | Adds strict-analysis baseline entries. |
| tests/phpstan/baselines-strict/argument.type.neon | Adds strict-analysis baseline entries. |
| tests/phpstan/analyse.php | Orchestrates default and strict PHPStan analyses and fix operations. |
| phpstan.neon.dist | Documents the relationship between the default and strict configurations. |
| phpstan-strict.neon.dist | Defines level-10 analysis paths, scanning configuration, and strict result caching. |
| composer.json | Adds separate default and strict analysis commands and updates combined and fix behavior. |
| .gitignore | Ignores local strict PHPStan configuration overrides. |
| .github/workflows/reusable-phpstan-static-analysis-v1.yml | Runs default and strict analyses in parallel and publishes separate results. |
| .github/workflows/phpstan-static-analysis.yml | Expands CI triggers for the strict configuration and baseline changes. |
| .github/workflows/phpstan-pull-request-comments.yml | Merges default and strict analysis results into pull-request comments. |
Review effort: Lite
…oth PHPStan analyses. Each analysis lists the files with errors that the base branch has changed, in which the line numbers it reports can be off in the head commit. The PHPStan comment only read the list of the default analysis, which leaves out a file whose only errors the strict analysis reports, so such an error could be linked to the wrong line. The lists of both analyses are now combined. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751
There was a problem hiding this comment.
🔵 Needs a closer look
Approval should wait for CI or human validation of the dual PHPStan analyses, baseline generation, and cross-job artifact/comment flow in the pinned PHPStan 2.3.6 environment.
No open issues 🎉
1 resolved since last review
Review effort: Lite
| ' ', | ||
| array_map( | ||
| 'escapeshellarg', | ||
| array_merge( array( PHP_BINARY, __FILE__ ), $args, array( "--config=$config", "--output-dir=$output" ) ) |
There was a problem hiding this comment.
for readability i'd normally add linebreaks here, but likely this doesnt matter.

PHPStan analyzes all of core at rule level 5. Much of the code added in recent releases, such as the Abilities API and the AI client, already meets or nearly meets level 10. This PR adds a second analysis that holds a selected set of paths to level 10, so that they can't regress, and so that the set can grow over time without raising the level for the whole project.
PHPStan has no per-path rule levels, so the second analysis has its own configuration,
phpstan-strict.neon.dist. The two analyses are nameddefaultandstrictrather than after their levels, since either level can be raised: the default one as more of core complies, and the strict one if PHPStan adds a level above 10. The strict configuration setslevel: 10rather thanmax, so that a PHPStan update does not raise it unannounced. It includesphpstan.neon.distand replaces itspathswith the strict paths, while scanning the rest ofsrc/wp-adminandsrc/wp-includesso their symbols are known. Becausetests/phpstan/base.neongives scanned files the same WordPress parser visitors as analyzed files, the strict paths get the same types as in a full analysis.What changes
WP_Error,WP_Post, andWP_Comment, and the PHPStan extensions intests/phpstan.tests/phpstan/baselines-strict/holds only what level 10 adds in the strict paths (27 errors, mostly missing iterable value types and return types). The strict configuration includes them through the directory's ownloader.php, in the same way thatphpstan.neon.disthas included its baselines since r65566 (Build/Test Tools: Include the PHPStan baselines through a PHP loader #16049). It also includes the default baselines, so an error reported by both analyses is baselined once.--config,composer phpstan:baselinesregenerates both directories, the default one first, since the strict baselines are only what the default ones leave. Namingphpstan-strict.neon.dist, or a localphpstan-strict.neonthat overrides it, writes tobaselines-strict/without--output-dir. A directory's loader is now written before the analysis rather than after, so a configuration that already includes the loader of a directory not created yet can have its first baselines generated.composer phpstannow runs both analyses throughtests/phpstan/analyse.phpand exits with the higher status. Paths and options such as--error-format,--level, and--configurationmake it run only the default analysis. A localphpstan.neonis still used for the default analysis, a localphpstan-strict.neonoverrides the strict configuration, and the strict run is skipped when the localphpstan.neonis already at the strict configuration's level or above.composer phpstan:defaultandcomposer phpstan:strictrun one.distconfiguration each.composer phpstan:fixhandles both baseline directories.phpstan dump-parametersand reports it with its results. The PR comment merges both results, lists an error reported by both once, and adds a Level column, showing the reported levels, when the strict analysis has errors. If the strict results are missing, the comment is left unchanged rather than marking those errors as resolved.tests/phpstan/README.mdgains a "Stricter analysis of selected paths" section, including how to add a path.The check name of the static analysis job changes, so the required status checks in branch protection may need updating.
Trac ticket: https://core.trac.wordpress.org/ticket/65817
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5 (medium effort)
Used for: Measuring level 10 errors across core to choose the strict paths, designing and implementing the configuration, runner, baseline generation, and CI changes, a code review of the result, and drafting this description; directed and reviewed by me.
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.