From 88f6839ce357faaa492568bba6dcd3fdd20633eb Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 15 Nov 2026 20:27:21 -0800 Subject: [PATCH 01/30] Build/Test Tools: Generate PHPStan baselines for more than one configuration. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/generate-baselines.php | 143 ++++++++++++++++++++++++--- 1 file changed, 131 insertions(+), 12 deletions(-) diff --git a/tests/phpstan/generate-baselines.php b/tests/phpstan/generate-baselines.php index 5a4ee33d9d5f9..86293bda0f3ed 100644 --- a/tests/phpstan/generate-baselines.php +++ b/tests/phpstan/generate-baselines.php @@ -17,6 +17,11 @@ * includes every baseline in that directory, so adding a newly split out baseline, * and retiring one that has reached zero, need no edit of the configuration. * + * Unless a configuration is named, this is done for each of DEFAULT_CONFIGS in + * turn: phpstan.neon.dist, which analyzes the whole codebase, and then + * phpstan-level-10.neon.dist, which holds selected paths to a stricter rule level + * and includes the former along with its baselines. + * * With `--prune`, nothing is analyzed: the baselines that no longer list any * entries are deleted. That completes running PHPStan with `--fix`, which removes * the entries of fixed errors in place but leaves a baseline it has emptied @@ -57,6 +62,21 @@ */ const DEFAULT_CONFIG = 'phpstan.neon.dist'; +/** + * The configurations processed when neither `--config` nor `--output-dir` is given, + * each with the directory its baselines are written to. + * + * They are processed in this order, which matters: phpstan-level-10.neon.dist + * includes phpstan.neon.dist along with its baselines, so its own are only what is + * left over once those are up to date. + * + * Relative to the repository root. + */ +const DEFAULT_CONFIGS = array( + DEFAULT_CONFIG => DEFAULT_OUTPUT_DIR, + 'phpstan-level-10.neon.dist' => 'tests/phpstan/baselines-level-10', +); + if ( 'cli' !== PHP_SAPI ) { fwrite( STDERR, "This script must be run from the command line.\n" ); exit( 1 ); @@ -74,7 +94,8 @@ array_shift( $args ); $config_option = DEFAULT_CONFIG; -$output_option = DEFAULT_OUTPUT_DIR; +$output_option = null; +$config_given = false; $memory_limit = '2G'; $only_identifiers = array(); $combined = false; @@ -121,11 +142,13 @@ if ( 1 === preg_match( '/^--config=(.+)$/', $arg, $matches ) ) { $config_option = $matches[1]; + $config_given = true; continue; } if ( 1 === preg_match( '/^--output-dir=(.+)$/', $arg, $matches ) ) { $output_option = $matches[1]; + $config_given = true; continue; } @@ -138,6 +161,45 @@ exit( 1 ); } +/* + * Without a configuration named, every default configuration is processed in turn, + * each by a run of this script naming it, so that each run is the same as one asked + * for directly. The first failure stops the rest, since each configuration after it + * depends on the baselines of those before it. + * + * `--combined` prints a single baseline, so it keeps to the first configuration. + */ +if ( ! $config_given && ! $combined ) { + foreach ( DEFAULT_CONFIGS as $config => $output ) { + $command = implode( + ' ', + array_map( + 'escapeshellarg', + array_merge( array( PHP_BINARY, __FILE__ ), $args, array( "--config=$config", "--output-dir=$output" ) ) + ) + ); + + fwrite( STDERR, "\n== $config ==\n\n" ); + + $exit_code = 0; + passthru( $command, $exit_code ); + + if ( 0 !== $exit_code ) { + exit( $exit_code ); + } + } + exit( 0 ); +} + +/* + * A default configuration named without an output directory writes to its own, + * so that naming phpstan-level-10.neon.dist alone cannot write its baselines over + * those of phpstan.neon.dist. + */ +if ( null === $output_option ) { + $output_option = DEFAULT_CONFIGS[ trim( normalize_path( $config_option ), '/' ) ] ?? DEFAULT_OUTPUT_DIR; +} + $config_path = $repo_root . '/' . ltrim( $config_option, '/' ); $output_dir = $repo_root . '/' . trim( $output_option, '/' ); @@ -338,6 +400,15 @@ static function () use ( $temp_config, $temp_baseline ): void { exit( 1 ); } +/* + * A configuration that turns off `reportUnmatchedIgnoredErrors` would also stop + * reporting the entries of its own baselines once they are stale, so each entry + * written for it turns that back on for itself. phpstan-level-10.neon.dist does + * so, because it drops the errors outside its strict paths before the ignores are + * matched against them. + */ +$report_unmatched = ! reports_unmatched_ignored_errors( $repo_root, $config_path, $memory_limit ); + /** * The entries of each error, grouped by the identifier of the error it suppresses. * @@ -359,7 +430,7 @@ static function () use ( $temp_config, $temp_baseline ): void { foreach ( $grouped as $entries ) { $all = array_merge( $all, $entries ); } - echo build_baseline( $all, $output_dir, "# Every identifier, combined.\n" ); + echo build_baseline( $all, $output_dir, "# Every identifier, combined.\n", $report_unmatched ); exit( 0 ); } @@ -396,19 +467,21 @@ static function () use ( $temp_config, $temp_baseline ): void { * The command each header gives for regenerating its baseline has to name the * configuration and the directory this run used, where they are not the * defaults. Without them, it would regenerate the default directory instead. + * A default configuration's own directory needs no naming, since naming the + * configuration alone writes there. */ $regenerate_options = ''; if ( DEFAULT_CONFIG !== $config_relative ) { $regenerate_options .= ' --config=' . $config_option; } -if ( ! $is_default_output_dir ) { +if ( ( DEFAULT_CONFIGS[ $config_relative ] ?? DEFAULT_OUTPUT_DIR ) !== trim( normalize_path( $output_option ), '/' ) ) { $regenerate_options .= ' --output-dir=' . $output_option; } foreach ( $grouped as $identifier => $entries ) { $written = file_put_contents( $output_dir . '/' . $identifier . '.neon', - build_baseline( $entries, $output_dir, build_baseline_header( $identifier, $regenerate_options ) ) + build_baseline( $entries, $output_dir, build_baseline_header( $identifier, $regenerate_options ), $report_unmatched ) ); if ( false === $written ) { @@ -468,6 +541,10 @@ function get_usage(): string { tests/phpstan/baselines/loader.php, so neither addition nor removal needs an edit of it. + Without --config or --output-dir, this is done for phpstan.neon.dist into + tests/phpstan/baselines, and then for phpstan-level-10.neon.dist into + tests/phpstan/baselines-level-10. The other options apply to both. + Usage: composer phpstan:baselines [-- ] @@ -478,16 +555,20 @@ function get_usage(): string { rather than left behind empty. Default: every identifier reported. --config= Configuration to analyze with, relative to the repository - root. Default: phpstan.neon.dist + root. Naming one processes only that configuration. + Default: both of the above. --output-dir= Where the per-identifier baselines are written, relative to the repository root. Paths inside them are written relative to this directory. A loader is written there too, which the configuration has to include. Baselines in other directories stay in force, so only the errors they leave are written. - Default: tests/phpstan/baselines + Default: the directory of the configuration named + above, or else tests/phpstan/baselines --combined Print one combined baseline to stdout instead of writing - per-identifier files. Nothing is written to disk. + per-identifier files. Nothing is written to disk. Only + phpstan.neon.dist is analyzed, unless --config names + another configuration. --prune Without analyzing anything, delete the baselines that no longer list any entries, such as one emptied by running PHPStan with --fix. With --identifier, only those @@ -760,6 +841,41 @@ function count_errors( array $entries ): int { return $total; } +/** + * Determines whether a configuration reports ignores that no longer match an error. + * + * The parameter is read from what PHPStan resolves, so that it reflects every + * file the configuration includes. Only its line 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. + * + * @param non-empty-string $repo_root Absolute path to the repository root. + * @param non-empty-string $config_path Absolute path to the configuration file. + * @param string $memory_limit Memory limit passed to PHPStan. + * @return bool Whether `reportUnmatchedIgnoredErrors` is on. + */ +function reports_unmatched_ignored_errors( string $repo_root, string $config_path, string $memory_limit ): bool { + $command = sprintf( + '%s dump-parameters --configuration=%s --json --memory-limit=%s', + escapeshellarg( $repo_root . '/vendor/bin/phpstan' ), + escapeshellarg( $config_path ), + escapeshellarg( $memory_limit ) + ); + + $output = array(); + $exit_code = 0; + exec( $command, $output, $exit_code ); + + foreach ( $output as $line ) { + if ( 1 === preg_match( '/^\s*"reportUnmatchedIgnoredErrors": (true|false),?$/', $line, $matches ) ) { + return 'true' === $matches[1]; + } + } + + fwrite( STDERR, "Could not read reportUnmatchedIgnoredErrors from the configuration (exit status $exit_code).\n" ); + exit( 1 ); +} + /** * Builds a baseline file in PHPStan's NEON format. * @@ -767,12 +883,14 @@ function count_errors( array $entries ): int { * be diffed against one it produced. Paths are rewritten relative to the file's * own directory, since that is what a NEON `path` resolves against. * - * @param list, path: non-empty-string}> $entries Baseline entries. - * @param non-empty-string $output_dir Directory the file is written to. - * @param string $header Comment block, or an empty string. + * @param list, path: non-empty-string}> $entries Baseline entries. + * @param non-empty-string $output_dir Directory the file is written to. + * @param string $header Comment block, or an empty string. + * @param bool $report_unmatched Whether each entry sets `reportUnmatched: true`, for a + * configuration that does not report unmatched ignores. * @return non-falsy-string Baseline file contents. */ -function build_baseline( array $entries, string $output_dir, string $header ): string { +function build_baseline( array $entries, string $output_dir, string $header, bool $report_unmatched ): string { $contents = ( '' === $header ? '' : $header . "\n" ) . "parameters:\n\tignoreErrors:\n"; foreach ( $entries as $entry ) { @@ -780,7 +898,8 @@ function build_baseline( array $entries, string $output_dir, string $header ): s . "\t\t\tmessage: " . quote_neon_value( $entry['message'] ) . "\n" . "\t\t\tidentifier: " . $entry['identifier'] . "\n" . "\t\t\tcount: " . $entry['count'] . "\n" - . "\t\t\tpath: " . get_relative_path( $output_dir, $entry['path'] ) . "\n"; + . "\t\t\tpath: " . get_relative_path( $output_dir, $entry['path'] ) . "\n" + . ( $report_unmatched ? "\t\t\treportUnmatched: true\n" : '' ); } return $contents; From 1d13e5be4a97000defa1bc127774a721e7814784 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 15 Nov 2026 20:27:40 -0800 Subject: [PATCH 02/30] Build/Test Tools: Hold selected paths to PHPStan rule level 10. `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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- .gitignore | 1 + phpstan-level-10.neon.dist | 97 +++++++++++++++ .../StrictPathsIgnoreErrorExtension.php | 114 ++++++++++++++++++ tests/phpstan/base.neon | 1 + .../baselines-level-10/argument.type.neon | 86 +++++++++++++ .../phpstan/baselines-level-10/cast.int.neon | 26 ++++ .../baselines-level-10/method.notFound.neon | 26 ++++ .../missingType.iterableValue.neon | 62 ++++++++++ .../missingType.return.neon | 44 +++++++ .../offsetAccess.nonOffsetAccessible.neon | 38 ++++++ .../baselines-level-10/return.type.neon | 26 ++++ 11 files changed, 521 insertions(+) create mode 100644 phpstan-level-10.neon.dist create mode 100644 tests/phpstan/StrictPathsIgnoreErrorExtension.php create mode 100644 tests/phpstan/baselines-level-10/argument.type.neon create mode 100644 tests/phpstan/baselines-level-10/cast.int.neon create mode 100644 tests/phpstan/baselines-level-10/method.notFound.neon create mode 100644 tests/phpstan/baselines-level-10/missingType.iterableValue.neon create mode 100644 tests/phpstan/baselines-level-10/missingType.return.neon create mode 100644 tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon create mode 100644 tests/phpstan/baselines-level-10/return.type.neon diff --git a/.gitignore b/.gitignore index 2d0178f495120..962f5698652b3 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ wp-tests-config.php /tests/phpunit/build /wp-cli.local.yml /phpstan.neon +/phpstan-level-10.neon /*.tsbuildinfo /jsdoc /composer.lock diff --git a/phpstan-level-10.neon.dist b/phpstan-level-10.neon.dist new file mode 100644 index 0000000000000..e01be51199efe --- /dev/null +++ b/phpstan-level-10.neon.dist @@ -0,0 +1,97 @@ +# PHPStan configuration holding selected parts of WordPress Core to rule level 10. +# +# phpstan.neon.dist analyzes the whole codebase at a lower rule level. This analyzes it at level 10, and reports +# only the errors in the paths listed under `strictPaths` below, so that code which already meets the stricter +# level, mostly code added in recent releases, keeps meeting it. `composer phpstan` runs both analyses. +# +# The analysis covers every path phpstan.neon.dist does, rather than only the strict paths, and filters the errors +# afterward. The WordPress-specific parser node visitors in tests/phpstan only rewrite the docblocks of the files +# that are analyzed, so narrowing the analyzed paths would read every function outside them without the types those +# visitors derive, such as the array shapes from hash notation. See tests/phpstan/README.md. +# +# To override this configuration, create a phpstan-level-10.neon which includes this file, in the same way as +# phpstan.neon overrides phpstan.neon.dist. +# +# https://phpstan.org/config-reference + +includes: + # Everything phpstan.neon.dist enforces: the base configuration, the strict rules, the errors ignored as not + # actionable, and its baselines. An error that both analyses report is baselined once, by phpstan.neon.dist. + - phpstan.neon.dist + + # Preexisting errors at this level in the strict paths, beyond those baselined by phpstan.neon.dist. They are + # organized and regenerated the same way, by `composer phpstan:baselines`, which rewrites both the files and the + # list between the markers. Do not edit that list by hand. + # phpstan:baselines start + - tests/phpstan/baselines-level-10/argument.type.neon + - tests/phpstan/baselines-level-10/cast.int.neon + - tests/phpstan/baselines-level-10/method.notFound.neon + - tests/phpstan/baselines-level-10/missingType.iterableValue.neon + - tests/phpstan/baselines-level-10/missingType.return.neon + - tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon + - tests/phpstan/baselines-level-10/return.type.neon + # phpstan:baselines end + +services: + # Drops every error reported outside the strict paths. + # See tests/phpstan/StrictPathsIgnoreErrorExtension.php. + - + class: WordPress\PHPStan\StrictPathsIgnoreErrorExtension + arguments: + paths: %strictPaths% + tags: + - phpstan.ignoreErrorExtension + +parametersSchema: + strictPaths: listOf(string()) + +parameters: + # https://phpstan.org/user-guide/rule-levels + level: 10 + + # The two analyses share the cache of what PHPStan reads from each file, since both parse every file the same way, + # but each needs its own result cache. Its metadata includes the rule level, so a shared one would be discarded by + # every run of the other analysis. + resultCachePath: %tmpDir%/resultCache-level-10.php + + # The errors outside the strict paths are dropped before the ignores are matched against them, so every + # `@phpstan-ignore` comment and baseline entry outside the strict paths would be reported as unmatched. Those are + # checked by phpstan.neon.dist instead. The entries of this configuration's own baselines each set + # `reportUnmatched: true`, which overrides this, so a stale one is still reported. + reportUnmatchedIgnoredErrors: false + + # The paths held to this rule level, relative to the repository root. A path ending in a slash is a directory, and + # covers every file below it. Any other path is a file. Each path must exist. + # + # Before adding a path, fix the errors this analysis reports in it, or baseline those that cannot be fixed yet. + strictPaths: + - src/wp-admin/includes/class-wp-filesystem-base.php + - src/wp-admin/includes/class-wp-filesystem-direct.php + - src/wp-admin/includes/class-wp-filesystem-ssh2.php + - src/wp-includes/abilities-api/ + - src/wp-includes/abilities-api.php + - src/wp-includes/ai-client/ + - src/wp-includes/ai-client.php + - src/wp-includes/class-wp-block-styles-registry.php + - src/wp-includes/class-wp-block-template.php + - src/wp-includes/class-wp-comment.php + - src/wp-includes/class-wp-connector-registry.php + - src/wp-includes/class-wp-error.php + - src/wp-includes/class-wp-post.php + - src/wp-includes/class-wp-url-pattern-prefixer.php + - src/wp-includes/html-api/class-wp-html-attribute-token.php + - src/wp-includes/html-api/class-wp-html-decoder.php + - src/wp-includes/html-api/class-wp-html-doctype-info.php + - src/wp-includes/html-api/class-wp-html-processor-state.php + - src/wp-includes/html-api/class-wp-html-span.php + - src/wp-includes/html-api/class-wp-html-stack-event.php + - src/wp-includes/html-api/class-wp-html-text-replacement.php + - src/wp-includes/html-api/class-wp-html-token.php + - src/wp-includes/html-api/class-wp-html-unsupported-exception.php + - src/wp-includes/l10n/class-wp-translations.php + - src/wp-includes/secrets/ + - src/wp-includes/secrets.php + - src/wp-includes/sitemaps.php + - src/wp-includes/speculative-loading.php + - src/wp-includes/style-engine/ + - tests/phpstan/ diff --git a/tests/phpstan/StrictPathsIgnoreErrorExtension.php b/tests/phpstan/StrictPathsIgnoreErrorExtension.php new file mode 100644 index 0000000000000..6f648d89fd061 --- /dev/null +++ b/tests/phpstan/StrictPathsIgnoreErrorExtension.php @@ -0,0 +1,114 @@ + + */ + private array $directories = array(); + + /** + * Absolute paths of the individual files that are reported, as keys. + * + * @var array + */ + private array $files = array(); + + /** + * Constructor. + * + * @param string[] $paths Paths relative to the repository root. A path ending in a slash is a + * directory, which covers every file below it. Any other path is a file. + * + * @throws InvalidArgumentException When a path does not exist, so that a renamed or deleted path + * cannot silently stop being checked. + */ + public function __construct( array $paths ) { + $root = self::normalize( dirname( __DIR__, 2 ) ) . '/'; + + foreach ( $paths as $path ) { + $relative = ltrim( self::normalize( $path ), '/' ); + $absolute = $root . $relative; + + if ( str_ends_with( $relative, '/' ) ) { + if ( ! is_dir( $absolute ) ) { + throw new InvalidArgumentException( "The strict path \"$path\" is not a directory." ); + } + $this->directories[] = $absolute; + } else { + if ( ! is_file( $absolute ) ) { + throw new InvalidArgumentException( "The strict path \"$path\" is not a file. End it with a slash if it is a directory." ); + } + $this->files[ $absolute ] = true; + } + } + } + + /** + * Determines whether an error is outside the listed paths, and so ignored. + * + * The path checked is the file the code reported on is in, which for an error in a trait is + * the trait's file rather than that of the class using it. + * + * @param Error $error Error reported. + * @param Node $node Node the error was reported on. + * @param Scope $scope Scope of the node. + * @return bool Whether to ignore the error. + */ + public function shouldIgnore( Error $error, Node $node, Scope $scope ): bool { + $file = self::normalize( $error->getFilePath() ); + + if ( isset( $this->files[ $file ] ) ) { + return false; + } + + foreach ( $this->directories as $directory ) { + if ( str_starts_with( $file, $directory ) ) { + return false; + } + } + + return true; + } + + /** + * Normalizes the directory separators of a path to forward slashes. + * + * @param string $path Path. + * @return string Normalized path. + */ + private static function normalize( string $path ): string { + return str_replace( '\\', '/', $path ); + } +} diff --git a/tests/phpstan/base.neon b/tests/phpstan/base.neon index 1c102ca47e7da..d62e1f2d039c9 100644 --- a/tests/phpstan/base.neon +++ b/tests/phpstan/base.neon @@ -305,6 +305,7 @@ parameters: - ApplyFiltersDynamicFunctionReturnTypeExtension.php - HookDocumentationRule.php - HookParamCountRule.php + - StrictPathsIgnoreErrorExtension.php bootstrapFiles: - bootstrap.php scanFiles: diff --git a/tests/phpstan/baselines-level-10/argument.type.neon b/tests/phpstan/baselines-level-10/argument.type.neon new file mode 100644 index 0000000000000..6958fdf80255c --- /dev/null +++ b/tests/phpstan/baselines-level-10/argument.type.neon @@ -0,0 +1,86 @@ +# PHPStan baseline for the `argument.type` errors in WordPress core. +# +# https://phpstan.org/error-identifiers/argument.type +# +# Each entry is scoped to a single file and carries an exact occurrence count, +# so that a new instance is reported as a new error rather than being absorbed +# silently. Fixing an occurrence therefore means decrementing or removing its +# entry here as part of the same change. +# +# The goal is to empty this file and delete it, along with the `includes` entry +# for it in phpstan-level-10.neon.dist. +# +# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# +# composer phpstan:baselines -- --identifier=argument.type +# +# which reruns the analysis with this file suppressed so the errors surface again. + +parameters: + ignoreErrors: + - + message: '#^Parameter \#1 \$object_or_string of function is_a expects object\|string, mixed given\.$#' + identifier: argument.type + count: 1 + path: ../../../src/wp-includes/abilities-api/class-wp-abilities-registry.php + reportUnmatched: true + - + message: '#^Parameter \#1 \$args of function wp_parse_args expects array\\|object\|string, mixed given\.$#' + identifier: argument.type + count: 2 + path: ../../../src/wp-includes/abilities-api/class-wp-ability.php + reportUnmatched: true + - + message: '#^Parameter \#1 \$name of method WordPress\\AiClientDependencies\\Psr\\Http\\Message\\MessageInterface\:\:withHeader\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: ../../../src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php + reportUnmatched: true + - + message: '#^Parameter \#1 \$wp_response of method WP_AI_Client_HTTP_Client\:\:create_psr_response\(\) expects array\, array given\.$#' + identifier: argument.type + count: 2 + path: ../../../src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php + reportUnmatched: true + - + message: '#^Parameter \#2 \$value of method WordPress\\AiClientDependencies\\Psr\\Http\\Message\\MessageInterface\:\:withHeader\(\) expects array\\|string, mixed given\.$#' + identifier: argument.type + count: 1 + path: ../../../src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php + reportUnmatched: true + - + message: '#^Parameter \#1 \$query of method wpdb\:\:query\(\) expects string, string\|null given\.$#' + identifier: argument.type + count: 1 + path: ../../../src/wp-includes/secrets/class-wp-secrets-key-manager.php + reportUnmatched: true + - + message: '#^Parameter \#1 \$table of method wpdb\:\:delete\(\) expects string, string\|null given\.$#' + identifier: argument.type + count: 1 + path: ../../../src/wp-includes/secrets/class-wp-secrets-key-manager.php + reportUnmatched: true + - + message: '#^Parameter \#1 \$table of method wpdb\:\:insert\(\) expects string, string\|null given\.$#' + identifier: argument.type + count: 1 + path: ../../../src/wp-includes/secrets/class-wp-secrets-key-manager.php + reportUnmatched: true + - + message: '#^Parameter \#4 \$options of static method WP_Style_Engine_CSS_Declarations\:\:filter_declaration\(\) expects array\{important\?\: bool, \.\.\.\}, mixed given\.$#' + identifier: argument.type + count: 1 + path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php + reportUnmatched: true + - + message: '#^Parameter \#3 \$options of method WP_Style_Engine_CSS_Declarations\:\:add_declaration\(\) expects array\{important\?\: bool, \.\.\.\}, mixed given\.$#' + identifier: argument.type + count: 1 + path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-rule.php + reportUnmatched: true + - + message: '#^Parameter \#1 \$should_prettify of method WP_Style_Engine_CSS_Rule\:\:get_css\(\) expects bool, mixed given\.$#' + identifier: argument.type + count: 1 + path: ../../../src/wp-includes/style-engine/class-wp-style-engine-processor.php + reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/cast.int.neon b/tests/phpstan/baselines-level-10/cast.int.neon new file mode 100644 index 0000000000000..d5d3e96b43697 --- /dev/null +++ b/tests/phpstan/baselines-level-10/cast.int.neon @@ -0,0 +1,26 @@ +# PHPStan baseline for the `cast.int` errors in WordPress core. +# +# https://phpstan.org/error-identifiers/cast.int +# +# Each entry is scoped to a single file and carries an exact occurrence count, +# so that a new instance is reported as a new error rather than being absorbed +# silently. Fixing an occurrence therefore means decrementing or removing its +# entry here as part of the same change. +# +# The goal is to empty this file and delete it, along with the `includes` entry +# for it in phpstan-level-10.neon.dist. +# +# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# +# composer phpstan:baselines -- --identifier=cast.int +# +# which reruns the analysis with this file suppressed so the errors surface again. + +parameters: + ignoreErrors: + - + message: '#^Cannot cast mixed to int\.$#' + identifier: cast.int + count: 1 + path: ../../../src/wp-includes/class-wp-post.php + reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/method.notFound.neon b/tests/phpstan/baselines-level-10/method.notFound.neon new file mode 100644 index 0000000000000..84edfa07f6902 --- /dev/null +++ b/tests/phpstan/baselines-level-10/method.notFound.neon @@ -0,0 +1,26 @@ +# PHPStan baseline for the `method.notFound` errors in WordPress core. +# +# https://phpstan.org/error-identifiers/method.notFound +# +# Each entry is scoped to a single file and carries an exact occurrence count, +# so that a new instance is reported as a new error rather than being absorbed +# silently. Fixing an occurrence therefore means decrementing or removing its +# entry here as part of the same change. +# +# The goal is to empty this file and delete it, along with the `includes` entry +# for it in phpstan-level-10.neon.dist. +# +# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# +# composer phpstan:baselines -- --identifier=method.notFound +# +# which reruns the analysis with this file suppressed so the errors surface again. + +parameters: + ignoreErrors: + - + message: '#^Call to an undefined method object\:\:usingRequestOptions\(\)\.$#' + identifier: method.notFound + count: 1 + path: ../../../src/wp-includes/ai-client/class-wp-ai-client-builder.php + reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/missingType.iterableValue.neon b/tests/phpstan/baselines-level-10/missingType.iterableValue.neon new file mode 100644 index 0000000000000..ed2de260b8754 --- /dev/null +++ b/tests/phpstan/baselines-level-10/missingType.iterableValue.neon @@ -0,0 +1,62 @@ +# PHPStan baseline for the `missingType.iterableValue` errors in WordPress core. +# +# https://phpstan.org/error-identifiers/missingType.iterableValue +# +# Each entry is scoped to a single file and carries an exact occurrence count, +# so that a new instance is reported as a new error rather than being absorbed +# silently. Fixing an occurrence therefore means decrementing or removing its +# entry here as part of the same change. +# +# The goal is to empty this file and delete it, along with the `includes` entry +# for it in phpstan-level-10.neon.dist. +# +# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# +# composer phpstan:baselines -- --identifier=missingType.iterableValue +# +# which reruns the analysis with this file suppressed so the errors surface again. + +parameters: + ignoreErrors: + - + message: '#^Function _wp_get_abilities_match_meta\(\) has parameter \$conditions with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../../../src/wp-includes/abilities-api.php + reportUnmatched: true + - + message: '#^Function _wp_get_abilities_match_meta\(\) has parameter \$meta with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../../../src/wp-includes/abilities-api.php + reportUnmatched: true + - + message: '#^Function wp_get_abilities\(\) has parameter \$args with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../../../src/wp-includes/abilities-api.php + reportUnmatched: true + - + message: '#^Function wp_ai_client_embedding\(\) has parameter \$input with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../../../src/wp-includes/ai-client.php + reportUnmatched: true + - + message: '#^Function wp_ai_client_prompt\(\) has parameter \$prompt with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../../../src/wp-includes/ai-client.php + reportUnmatched: true + - + message: '#^Method WP_Style_Engine_CSS_Declarations\:\:get_declaration_options\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php + reportUnmatched: true + - + message: '#^Property WP_Style_Engine_CSS_Declarations\:\:\$declaration_options type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php + reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/missingType.return.neon b/tests/phpstan/baselines-level-10/missingType.return.neon new file mode 100644 index 0000000000000..77a2d175d3af6 --- /dev/null +++ b/tests/phpstan/baselines-level-10/missingType.return.neon @@ -0,0 +1,44 @@ +# PHPStan baseline for the `missingType.return` errors in WordPress core. +# +# https://phpstan.org/error-identifiers/missingType.return +# +# Each entry is scoped to a single file and carries an exact occurrence count, +# so that a new instance is reported as a new error rather than being absorbed +# silently. Fixing an occurrence therefore means decrementing or removing its +# entry here as part of the same change. +# +# The goal is to empty this file and delete it, along with the `includes` entry +# for it in phpstan-level-10.neon.dist. +# +# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# +# composer phpstan:baselines -- --identifier=missingType.return +# +# which reruns the analysis with this file suppressed so the errors surface again. + +parameters: + ignoreErrors: + - + message: '#^Method WP_Style_Engine_CSS_Rules_Store\:\:remove_all_stores\(\) has no return type specified\.$#' + identifier: missingType.return + count: 1 + path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php + reportUnmatched: true + - + message: '#^Method WP_Style_Engine_CSS_Rules_Store\:\:remove_rule\(\) has no return type specified\.$#' + identifier: missingType.return + count: 1 + path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php + reportUnmatched: true + - + message: '#^Method WP_Style_Engine_CSS_Rules_Store\:\:set_name\(\) has no return type specified\.$#' + identifier: missingType.return + count: 1 + path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php + reportUnmatched: true + - + message: '#^Method WP_Style_Engine_Processor\:\:combine_rules_selectors\(\) has no return type specified\.$#' + identifier: missingType.return + count: 1 + path: ../../../src/wp-includes/style-engine/class-wp-style-engine-processor.php + reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon b/tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon new file mode 100644 index 0000000000000..7f7d53f5dc74d --- /dev/null +++ b/tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon @@ -0,0 +1,38 @@ +# PHPStan baseline for the `offsetAccess.nonOffsetAccessible` errors in WordPress core. +# +# https://phpstan.org/error-identifiers/offsetAccess.nonOffsetAccessible +# +# Each entry is scoped to a single file and carries an exact occurrence count, +# so that a new instance is reported as a new error rather than being absorbed +# silently. Fixing an occurrence therefore means decrementing or removing its +# entry here as part of the same change. +# +# The goal is to empty this file and delete it, along with the `includes` entry +# for it in phpstan-level-10.neon.dist. +# +# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# +# composer phpstan:baselines -- --identifier=offsetAccess.nonOffsetAccessible +# +# which reruns the analysis with this file suppressed so the errors surface again. + +parameters: + ignoreErrors: + - + message: '#^Cannot access offset ''annotations'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: ../../../src/wp-includes/abilities-api/class-wp-ability.php + reportUnmatched: true + - + message: '#^Cannot access offset ''public'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: ../../../src/wp-includes/abilities-api/class-wp-ability.php + reportUnmatched: true + - + message: '#^Cannot access offset ''show_in_rest'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: ../../../src/wp-includes/abilities-api/class-wp-ability.php + reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/return.type.neon b/tests/phpstan/baselines-level-10/return.type.neon new file mode 100644 index 0000000000000..9d92f3ad04917 --- /dev/null +++ b/tests/phpstan/baselines-level-10/return.type.neon @@ -0,0 +1,26 @@ +# PHPStan baseline for the `return.type` errors in WordPress core. +# +# https://phpstan.org/error-identifiers/return.type +# +# Each entry is scoped to a single file and carries an exact occurrence count, +# so that a new instance is reported as a new error rather than being absorbed +# silently. Fixing an occurrence therefore means decrementing or removing its +# entry here as part of the same change. +# +# The goal is to empty this file and delete it, along with the `includes` entry +# for it in phpstan-level-10.neon.dist. +# +# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# +# composer phpstan:baselines -- --identifier=return.type +# +# which reruns the analysis with this file suppressed so the errors surface again. + +parameters: + ignoreErrors: + - + message: '#^Method WP_Ability_Categories_Registry\:\:get_all_registered\(\) should return array\ but returns array\\.$#' + identifier: return.type + count: 1 + path: ../../../src/wp-includes/abilities-api/class-wp-ability-categories-registry.php + reportUnmatched: true From e1d41e3c5bce285e84d6ef356af7bd79feae81a1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 15 Nov 2026 20:29:34 -0800 Subject: [PATCH 03/30] Build/Test Tools: Run both PHPStan analyses from `composer phpstan`. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- composer.json | 6 +- tests/phpstan/analyse.php | 170 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 tests/phpstan/analyse.php diff --git a/composer.json b/composer.json index dd7f57d5b6313..b4b6ca8ec79f6 100644 --- a/composer.json +++ b/composer.json @@ -75,9 +75,11 @@ } }, "scripts": { - "phpstan": "@php ./vendor/bin/phpstan analyse --memory-limit=2G", + "phpstan": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpstan/analyse.php --memory-limit=2G" ], + "phpstan:level-5": "@php ./vendor/bin/phpstan analyse --configuration=phpstan.neon.dist --memory-limit=2G", + "phpstan:level-10": "@php ./vendor/bin/phpstan analyse --configuration=phpstan-level-10.neon.dist --memory-limit=2G", "phpstan:baselines": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpstan/generate-baselines.php" ], - "phpstan:fix": [ "Composer\\Config::disableProcessTimeout", "@phpstan --configuration=phpstan.neon.dist --fix", "@phpstan:baselines --prune", "@phpstan --configuration=phpstan.neon.dist" ], + "phpstan:fix": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpstan/analyse.php --memory-limit=2G --fix" ], "compat": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --standard=phpcompat.xml.dist --report=summary,source", "format": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf --report=summary,source", "lint": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --report=summary,source", diff --git a/tests/phpstan/analyse.php b/tests/phpstan/analyse.php new file mode 100644 index 0000000000000..21499d5493d46 --- /dev/null +++ b/tests/phpstan/analyse.php @@ -0,0 +1,170 @@ + 1 ) { + exit( $status ); + } + } + + $status = run( 'Deleting the baselines left without entries', PHP_BINARY, array( __DIR__ . '/generate-baselines.php', '--prune' ), false ); + if ( 0 !== $status ) { + exit( $status ); + } + + $exit_code = 0; + foreach ( array( PROJECT_CONFIG, STRICT_CONFIG ) as $config ) { + $exit_code = max( $exit_code, run( "Analyzing with $config", $phpstan, array_merge( array( "--configuration=$config" ), $args ) ) ); + } + exit( $exit_code ); +} + +$local_config = $repo_root . '/phpstan.neon'; +$strict_config = is_file( $repo_root . '/phpstan-level-10.neon' ) ? 'phpstan-level-10.neon' : STRICT_CONFIG; + +// PHPStan reads phpstan.neon in place of phpstan.neon.dist by itself, so the first analysis names neither. +$exit_code = run( 'Analyzing with ' . ( is_file( $local_config ) ? 'phpstan.neon' : PROJECT_CONFIG ), $phpstan, $args ); + +if ( is_file( $local_config ) && is_strictest_level( $phpstan, $local_config ) ) { + fwrite( STDERR, "\nSkipping $strict_config: phpstan.neon already analyzes every path at level 10.\n" ); + exit( $exit_code ); +} + +exit( max( $exit_code, run( "Analyzing the strict paths with $strict_config", $phpstan, array_merge( array( "--configuration=$strict_config" ), $args ) ) ) ); + +/** + * Runs a command with a heading, passing its output through. + * + * The heading goes to stderr, so that what the command writes to stdout, such as + * a report in a machine-readable format, is left as it is. + * + * @param string $heading Heading describing the run. + * @param string $command Command to run. + * @param string[] $args Arguments, each escaped for the shell. + * @param bool $is_analysis Whether the command is a PHPStan analysis, to which `analyse` is passed first. + * @return int Exit status of the command. + */ +function run( string $heading, string $command, array $args, bool $is_analysis = true ): int { + fwrite( STDERR, "\n== $heading ==\n\n" ); + + $parts = array( escapeshellarg( $command ) ); + if ( $is_analysis ) { + $parts[] = 'analyse'; + } + foreach ( $args as $arg ) { + $parts[] = escapeshellarg( $arg ); + } + + $exit_code = 0; + passthru( implode( ' ', $parts ), $exit_code ); + + return $exit_code; +} + +/** + * Determines whether a configuration analyzes at the strictest rule level. + * + * 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. + * + * @param string $phpstan Path to the PHPStan executable. + * @param string $config Absolute path to the configuration file. + * @return bool Whether the configuration's rule level is 10 or `max`. + */ +function is_strictest_level( string $phpstan, string $config ): bool { + $output = array(); + $exit_code = 0; + exec( sprintf( '%s dump-parameters --configuration=%s --json 2>/dev/null', escapeshellarg( $phpstan ), escapeshellarg( $config ) ), $output, $exit_code ); + + foreach ( $output as $line ) { + if ( 1 === preg_match( '/^\s*"level": ("max"|"?\d+"?),?$/', $line, $matches ) ) { + $level = trim( $matches[1], '"' ); + return 'max' === $level || (int) $level >= 10; + } + } + + return false; +} From 772bd563914bc261f6ff80f2522c0994d7225ec0 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 15 Nov 2026 20:32:10 -0800 Subject: [PATCH 04/30] Build/Test Tools: Run the level 10 PHPStan analysis in CI. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- .../phpstan-pull-request-comments.yml | 76 +++++++++++++++++-- .../reusable-phpstan-static-analysis-v1.yml | 73 ++++++++++++++---- 2 files changed, 127 insertions(+), 22 deletions(-) diff --git a/.github/workflows/phpstan-pull-request-comments.yml b/.github/workflows/phpstan-pull-request-comments.yml index d1c38cc83fd10..32f647bf561b3 100644 --- a/.github/workflows/phpstan-pull-request-comments.yml +++ b/.github/workflows/phpstan-pull-request-comments.yml @@ -57,6 +57,19 @@ jobs: run-id: ${{ github.event.workflow_run.id }} github-token: ${{ github.token }} + # The results of the analysis holding selected paths to rule level 10. A pull request whose branch does not have + # that analysis yet uploads none, which is fine. Whether they were expected is decided from the results above. + - name: Download the results of the level 10 analysis + id: download-level-10 + if: ${{ steps.download.outcome == 'success' }} + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + continue-on-error: true + with: + name: phpstan-results-level-10 + path: ${{ runner.temp }}/phpstan-results-level-10 + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + - name: Create, update, or resolve the PHPStan comment if: ${{ steps.download.outcome == 'success' }} uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 @@ -99,6 +112,49 @@ jobs: message: ( asString( error.message ) ?? '' ).slice( 0, 1000 ), identifier: /^[A-Za-z0-9.]+$/.test( error.identifier ) ? error.identifier : null, ignorable: error.ignorable === true, + // The rule level of the analysis that reported the error: 10 for the paths phpstan-level-10.neon.dist + // holds to it, and 5 for everything else, including history recorded before there was a level 10. + level: error.level === 10 ? 10 : 5, + } ); + + // The paths held to rule level 10 are analyzed a second time, and that analysis uploads its results + // separately. The results above list the analyses the run made, and when the level 10 one is among them + // but its results are missing, the comment is left as it is: every error that only analysis reported + // would otherwise be shown as resolved. A run from a branch that does not have that analysis yet lists + // none, and has only these results. + const expectsLevel10 = Array.isArray( results.analyses ) && results.analyses.includes( 'level-10' ); + let level10Errors = []; + if ( expectsLevel10 ) { + let level10Results = null; + try { + level10Results = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-results-level-10/results.json`, 'utf8' ) ); + } catch ( error ) { + core.info( `The results of the level 10 analysis are missing, so the comment is left as it is: ${ error.message }` ); + return; + } + if ( level10Results?.pull_request !== issue_number || ! Array.isArray( level10Results.errors ) ) { + core.setFailed( 'The results of the level 10 analysis are malformed.' ); + return; + } + level10Errors = level10Results.errors.map( ( error ) => normalize( { ...error, level: 10 } ) ); + } + + // The level 10 analysis includes everything the other one does, so an error it reports at a lower level is + // reported by both. Such an error is listed once, as found by the analysis of the whole codebase, and the + // level 10 one only adds what is left over. Errors are matched as they are below, apart from their line. + const errorKey = ( error ) => JSON.stringify( [ error.file, error.identifier, error.message ] ); + const level5Counts = new Map(); + const level5Errors = results.errors.map( normalize ); + for ( const error of level5Errors ) { + level5Counts.set( errorKey( error ), ( level5Counts.get( errorKey( error ) ) ?? 0 ) + 1 ); + } + const level10Only = level10Errors.filter( ( error ) => { + const count = level5Counts.get( errorKey( error ) ) ?? 0; + if ( count > 0 ) { + level5Counts.set( errorKey( error ), count - 1 ); + return false; + } + return true; } ); // An error is recognized from one run to the next by its file, identifier and message, but not its line, @@ -107,10 +163,10 @@ jobs: // is fixed or added, those after it shift to the history of the one before or after, so their first reports // can be off, and the one shown as resolved or new is the last rather than the one that was. That is rarer // than lines being added or removed above them, which would throw off matching them by line. - const errors = results.errors.map( normalize ); + const errors = [ ...level5Errors, ...level10Only ]; const occurrences = new Map(); for ( const error of [ ...errors ].sort( ( a, b ) => ( a.line ?? 0 ) - ( b.line ?? 0 ) ) ) { - const key = JSON.stringify( [ error.file, error.identifier, error.message ] ); + const key = errorKey( error ); const occurrence = occurrences.get( key ) ?? 0; occurrences.set( key, occurrence + 1 ); error.key = `${ key }#${ occurrence }`; @@ -215,10 +271,13 @@ jobs: : `The ${ rows.length } errors are not listed here, to keep this comment short. They are listed in ${ where }.`; } const more = `…and ${ rows.length - shown.length } more, which are listed in ${ where }.`; + // The rule level is only shown in a table listing an error from the level 10 analysis, so that one listing + // only errors from the analysis of the whole codebase looks as it did before there were two. + const withLevel = shown.some( ( error ) => error.level === 10 ); const lines = [ - `| Location | Error | Identifier | First reported |${ withResolution ? ' Resolved |' : '' }`, - `| --- | --- | --- | --- |${ withResolution ? ' --- |' : '' }`, - ...shown.map( ( error ) => `| ${ location( error ) } | ${ code( error.message ) } | ${ identifier( error ) } | ${ commit( error.introduced ) } |${ withResolution ? ` ${ commit( error.fixed ) } |` : '' }` ), + `| Location | Error | Identifier |${ withLevel ? ' Level |' : '' } First reported |${ withResolution ? ' Resolved |' : '' }`, + `| --- | --- | --- |${ withLevel ? ' --- |' : '' } --- |${ withResolution ? ' --- |' : '' }`, + ...shown.map( ( error ) => `| ${ location( error ) } | ${ code( error.message ) } | ${ identifier( error ) } |${ withLevel ? ` ${ error.level } |` : '' } ${ commit( error.introduced ) } |${ withResolution ? ` ${ commit( error.fixed ) } |` : '' }` ), ]; if ( shown.length < rows.length ) { lines.push( '', more ); @@ -248,6 +307,9 @@ jobs: `> ${ filesWithLinesOff.size === 1 ? 'A file with errors has' : `${ filesWithLinesOff.size } files with errors have` } changed in ${ code( pr.base.ref ) } since this branch was last updated, so the line numbers reported in ${ filesWithLinesOff.size === 1 ? 'it' : 'them' } may be off and are not linked. Merge the latest ${ code( pr.base.ref ) } into this branch for accurate links.`, ].join( '\n' ) ); } + if ( active.some( ( error ) => error.level === 10 ) ) { + sections.push( `An error at level 10 is in a path that ${ code( 'phpstan-level-10.neon.dist' ) } holds to rule level 10, which the rest of the codebase is not yet held to. See [Stricter analysis of selected paths](${ readmeUrl }#stricter-analysis-of-selected-paths).` ); + } } else { // Resolved by the last commit that resolved anything, so that later commits do not change the comment. const resolvedBy = resolved.at( -1 )?.fixed ?? run.head_sha; @@ -316,8 +378,8 @@ jobs: // The errors tracked are taken in the order they are listed, so that each one listed keeps its history. const tracked = [ ...unignorable, ...ignorable ].slice( 0, trackedLimit ).concat( resolved ).map( ( error ) => { - const { key, file, line, message, identifier, ignorable, introduced, seen, fixed } = error; - return { key, file, line: lineMayBeOff( error ) ? null : line, message, identifier, ignorable, introduced, seen, fixed }; + const { key, file, line, message, identifier, ignorable, level, introduced, seen, fixed } = error; + return { key, file, line: lineMayBeOff( error ) ? null : line, message, identifier, ignorable, level, introduced, seen, fixed }; } ); sections.push( `` ); diff --git a/.github/workflows/reusable-phpstan-static-analysis-v1.yml b/.github/workflows/reusable-phpstan-static-analysis-v1.yml index 5474a810164cd..4d56f14b2c5cc 100644 --- a/.github/workflows/reusable-phpstan-static-analysis-v1.yml +++ b/.github/workflows/reusable-phpstan-static-analysis-v1.yml @@ -21,8 +21,13 @@ permissions: {} jobs: # Runs PHP static analysis tests. # - # Violations are reported inline with annotations. For pull requests, the results are also uploaded - # as an artifact, which the PHPStan Pull Request Comments workflow summarizes in a comment. + # Core is analyzed twice, in parallel: the whole codebase with phpstan.neon.dist, and the paths held to rule level 10 + # with phpstan-level-10.neon.dist. The second analyzes every path too, since narrowing them would change the types + # the WordPress-specific extensions derive, and reports only the errors in its strict paths. See + # tests/phpstan/README.md. + # + # Violations are reported inline with annotations. For pull requests, the results of each analysis are also uploaded + # as an artifact, and the PHPStan Pull Request Comments workflow combines them in a comment. # # Performs the following steps: # - Checks out the repository. @@ -39,11 +44,28 @@ jobs: # - Saves the PHPStan result cache. # - Ensures version-controlled files are not modified or deleted. phpstan: - name: Run PHP static analysis + name: Run PHP static analysis (${{ matrix.label }}) runs-on: ubuntu-26.04 permissions: contents: read timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + include: + # The artifact of the analysis of the whole codebase keeps the name it had before there were two, which is + # the name the PHPStan Pull Request Comments workflow on trunk requires. That way the comment is kept up to + # date for a pull request whose branch does not have the second analysis yet. + - analysis: level-5 + label: all paths + baselines: tests/phpstan/baselines + script: phpstan:level-5 + artifact: phpstan-results + - analysis: level-10 + label: level 10 paths + baselines: tests/phpstan/baselines-level-10 + script: phpstan:level-10 + artifact: phpstan-results-level-10 steps: # For a pull request, the parents of the merge commit are fetched too, to find the files that the base branch @@ -92,16 +114,21 @@ jobs: # merged this commit yet runs the workflow it has, and that workflow would prefix-match the # caches written here: it would analyse without the extensions against reflection derived with # them. A name of its own leaves those runs restoring only their own caches. + # + # Each analysis caches separately. Its result cache records the rule level, and is discarded + # by a run at another level, so restoring the other analysis's cache would gain nothing. - name: Cache PHP Static Analysis scan cache uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: path: .cache # This is defined in the base.neon file. - key: "phpstan-analysis-cache-${{ hashFiles('phpstan.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}-${{ github.run_id }}" + key: "phpstan-analysis-cache-${{ matrix.analysis }}-${{ hashFiles('phpstan.neon.dist', 'phpstan-level-10.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}-${{ github.run_id }}" restore-keys: | - phpstan-analysis-cache-${{ hashFiles('phpstan.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}- + phpstan-analysis-cache-${{ matrix.analysis }}-${{ hashFiles('phpstan.neon.dist', 'phpstan-level-10.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}- - name: Run PHP static analysis tests id: phpstan + env: + SCRIPT: ${{ matrix.script }} run: | # The report is written to a file for the steps below, which turn it into annotations, # the pull request comment, and a check for errors that cannot be reported as warnings. @@ -111,7 +138,7 @@ jobs: # The step shell exits on the first failing command, which would also end the step on # the status of 1 that PHPStan uses for reporting errors. Capture the status instead. status=0 - composer run phpstan -- -vvv --error-format=json > "${RUNNER_TEMP}/phpstan-report.json" || status=$? + composer run "${SCRIPT}" -- -vvv --error-format=json > "${RUNNER_TEMP}/phpstan-report.json" || status=$? # PHPStan exits 1 when it has errors to report, which is the expected case here and # is what the annotations are for. Anything higher means it did not finish at all. @@ -132,10 +159,16 @@ jobs: - name: Report the analysis results id: report uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + ANALYSIS: ${{ matrix.analysis }} with: script: | const fs = require( 'fs' ); + // Annotations from the stricter analysis say so, since the same code can pass the other one. + const analysis = process.env.ANALYSIS; + const titlePrefix = analysis === 'level-10' ? 'PHPStan (level 10)' : 'PHPStan'; + const report = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-report.json`, 'utf8' ) ); const workspace = `${ process.env.GITHUB_WORKSPACE }/`; @@ -165,7 +198,7 @@ jobs: const fixHint = 'This can be fixed automatically by running `composer phpstan:fix` (or `npm run typecheck:php:fix`).'; for ( const error of errors ) { - const properties = { title: error.identifier ? `PHPStan: ${ error.identifier }` : 'PHPStan' }; + const properties = { title: error.identifier ? `${ titlePrefix }: ${ error.identifier }` : titlePrefix }; if ( error.file ) { properties.file = error.file; } @@ -186,6 +219,10 @@ jobs: // The commit analyzed is the pull request merged into its base branch, whose second parent is the head // commit. The files with errors that differ between the two are those the base branch has changed, in // which the line numbers reported can be off in the head commit. + // + // Each analysis writes its own results. Those of the analysis of the whole codebase also list every + // analysis the run makes, so that the comment is not updated from only some of them: an error missing + // because its analysis did not upload results would otherwise be shown as resolved. if ( context.eventName === 'pull_request' ) { let changedInBase = []; try { @@ -200,6 +237,8 @@ jobs: fs.mkdirSync( `${ process.env.RUNNER_TEMP }/phpstan-results`, { recursive: true } ); fs.writeFileSync( `${ process.env.RUNNER_TEMP }/phpstan-results/results.json`, JSON.stringify( { pull_request: context.payload.pull_request.number, + analysis, + ...( analysis === 'level-5' ? { analyses: [ 'level-5', 'level-10' ] } : {} ), changed_in_base: changedInBase, errors: errors.map( ( { tip, fixable, ...error } ) => error ), } ) ); @@ -211,7 +250,7 @@ jobs: uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 if: ${{ github.event_name == 'pull_request' && steps.report.outcome == 'success' }} with: - name: phpstan-results + name: ${{ matrix.artifact }} path: ${{ runner.temp }}/phpstan-results/ # Some errors cannot be ignored, so they cannot be reported as warnings either. Most often @@ -229,7 +268,8 @@ jobs: - name: Check for errors that cannot be reported as warnings if: ${{ !cancelled() }} env: - BASELINES_URL: ${{ github.server_url }}/${{ github.repository }}/tree/${{ github.sha }}/tests/phpstan/baselines + BASELINES_URL: ${{ github.server_url }}/${{ github.repository }}/tree/${{ github.sha }}/${{ matrix.baselines }} + LABEL: ${{ matrix.label }} README_URL: ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/tests/phpstan/README.md run: | # This step runs even when the analysis above it failed, in which case the report may @@ -264,8 +304,11 @@ jobs: # # A newline renders as a line break rather than a space, so each paragraph is one # line however long that makes it, and the rendered summary wraps to its own width. + # + # The heading names the analysis whose baselines are out of date, which is filled in for + # the LABEL placeholder when the summary is written, since the heredoc expands nothing. baselines_summary=$( cat <<'SUMMARY' - ## PHPStan baselines are out of date + ## PHPStan baselines are out of date (LABEL) An ignored error no longer occurs, or occurs a different number of times, so PHPStan reported it under an `ignore.unmatched` or `ignore.count` identifier. @@ -283,7 +326,7 @@ jobs: composer phpstan:fix ``` - That runs PHPStan with `--fix`, which lowers the counts in the files under [`tests/phpstan/baselines`][baselines], removes the entries that no longer match, and removes any `@phpstan-ignore` annotation in the code that no longer ignores anything. It then deletes any baseline left with no entries. + That runs PHPStan with `--fix`, which lowers the counts in [the baselines][baselines], removes the entries that no longer match, and removes any `@phpstan-ignore` annotation in the code that no longer ignores anything. It then deletes any baseline left with no entries. Alternatively, regenerate the baselines with `npm run typecheck:php:baselines` or `composer phpstan:baselines`. That also deletes any baseline whose errors are now all fixed, but it does not clear an `@phpstan-ignore` annotation. @@ -294,14 +337,14 @@ jobs: if [ "${ignore_errors}" -gt 0 ]; then { - printf '%s\n\n' "${baselines_summary}" + printf '%s\n\n' "${baselines_summary/LABEL/${LABEL}}" echo "[baselines]: ${BASELINES_URL}" echo "[readme]: ${README_URL}" } >> "${GITHUB_STEP_SUMMARY}" - echo "::error title=PHPStan baselines are out of date::An ignored error no longer occurs, or occurs a different number of times. If you fixed it, that is expected: run \`npm run typecheck:php:fix\` or \`composer phpstan:fix\` and commit the updated baselines. See ${README_URL}" + echo "::error title=PHPStan baselines are out of date (${LABEL})::An ignored error no longer occurs, or occurs a different number of times. If you fixed it, that is expected: run \`npm run typecheck:php:fix\` or \`composer phpstan:fix\` and commit the updated baselines. See ${README_URL}" else - echo "::error title=PHPStan reported errors that cannot be ignored::PHPStan reported ${unignorable} error(s) that cannot be ignored or reported as warnings. See the error annotations for details, and ${README_URL} for how to run the analysis locally." + echo "::error title=PHPStan reported errors that cannot be ignored (${LABEL})::PHPStan reported ${unignorable} error(s) that cannot be ignored or reported as warnings. See the error annotations for details, and ${README_URL} for how to run the analysis locally." fi exit 1 @@ -311,7 +354,7 @@ jobs: if: ${{ !cancelled() }} with: path: .cache - key: "phpstan-analysis-cache-${{ hashFiles('phpstan.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}-${{ github.run_id }}" + key: "phpstan-analysis-cache-${{ matrix.analysis }}-${{ hashFiles('phpstan.neon.dist', 'phpstan-level-10.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}-${{ github.run_id }}" - name: Ensure version-controlled files are not modified or deleted run: git diff --exit-code From e81d6a530f97e12b47e225f7b98e7a8e6ab49d8b Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 15 Nov 2026 20:44:10 -0800 Subject: [PATCH 05/30] Build/Test Tools: Analyze only the strict paths at PHPStan level 10. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- .../reusable-phpstan-static-analysis-v1.yml | 4 +- phpstan-level-10.neon.dist | 79 ++++++------ .../StrictPathsIgnoreErrorExtension.php | 114 ------------------ tests/phpstan/base.neon | 1 - .../baselines-level-10/argument.type.neon | 11 -- .../phpstan/baselines-level-10/cast.int.neon | 1 - .../baselines-level-10/method.notFound.neon | 1 - .../missingType.iterableValue.neon | 7 -- .../missingType.return.neon | 4 - .../offsetAccess.nonOffsetAccessible.neon | 3 - .../baselines-level-10/return.type.neon | 1 - tests/phpstan/generate-baselines.php | 61 ++-------- 12 files changed, 49 insertions(+), 238 deletions(-) delete mode 100644 tests/phpstan/StrictPathsIgnoreErrorExtension.php diff --git a/.github/workflows/reusable-phpstan-static-analysis-v1.yml b/.github/workflows/reusable-phpstan-static-analysis-v1.yml index 4d56f14b2c5cc..d3ae7b16cf553 100644 --- a/.github/workflows/reusable-phpstan-static-analysis-v1.yml +++ b/.github/workflows/reusable-phpstan-static-analysis-v1.yml @@ -22,9 +22,7 @@ jobs: # Runs PHP static analysis tests. # # Core is analyzed twice, in parallel: the whole codebase with phpstan.neon.dist, and the paths held to rule level 10 - # with phpstan-level-10.neon.dist. The second analyzes every path too, since narrowing them would change the types - # the WordPress-specific extensions derive, and reports only the errors in its strict paths. See - # tests/phpstan/README.md. + # with phpstan-level-10.neon.dist. See tests/phpstan/README.md. # # Violations are reported inline with annotations. For pull requests, the results of each analysis are also uploaded # as an artifact, and the PHPStan Pull Request Comments workflow combines them in a comment. diff --git a/phpstan-level-10.neon.dist b/phpstan-level-10.neon.dist index e01be51199efe..21b43d4ce740f 100644 --- a/phpstan-level-10.neon.dist +++ b/phpstan-level-10.neon.dist @@ -1,13 +1,13 @@ # PHPStan configuration holding selected parts of WordPress Core to rule level 10. # -# phpstan.neon.dist analyzes the whole codebase at a lower rule level. This analyzes it at level 10, and reports -# only the errors in the paths listed under `strictPaths` below, so that code which already meets the stricter -# level, mostly code added in recent releases, keeps meeting it. `composer phpstan` runs both analyses. +# phpstan.neon.dist analyzes the whole codebase at a lower rule level. This analyzes only the paths listed under +# `paths!` below, at level 10, so that code which already meets the stricter level, mostly code added in recent +# releases, keeps meeting it. `composer phpstan` runs both analyses. # -# The analysis covers every path phpstan.neon.dist does, rather than only the strict paths, and filters the errors -# afterward. The WordPress-specific parser node visitors in tests/phpstan only rewrite the docblocks of the files -# that are analyzed, so narrowing the analyzed paths would read every function outside them without the types those -# visitors derive, such as the array shapes from hash notation. See tests/phpstan/README.md. +# The rest of core is scanned rather than analyzed, so that what the strict paths use is known. A scanned file is read +# with the same WordPress-specific parser node visitors as an analyzed one (see the redefinition of +# `currentPhpVersionSimpleParser` in tests/phpstan/base.neon), so a function outside the strict paths has the same +# types here, such as the array shapes from hash notation, as in the analysis of the whole codebase. # # To override this configuration, create a phpstan-level-10.neon which includes this file, in the same way as # phpstan.neon overrides phpstan.neon.dist. @@ -16,7 +16,9 @@ includes: # Everything phpstan.neon.dist enforces: the base configuration, the strict rules, the errors ignored as not - # actionable, and its baselines. An error that both analyses report is baselined once, by phpstan.neon.dist. + # actionable, and its baselines. An error that both analyses report is baselined once, by phpstan.neon.dist. The + # entries for files this does not analyze are not reported as unmatched, since PHPStan only reports an entry when + # what it ignores is within the analysis. - phpstan.neon.dist # Preexisting errors at this level in the strict paths, beyond those baselined by phpstan.neon.dist. They are @@ -32,45 +34,26 @@ includes: - tests/phpstan/baselines-level-10/return.type.neon # phpstan:baselines end -services: - # Drops every error reported outside the strict paths. - # See tests/phpstan/StrictPathsIgnoreErrorExtension.php. - - - class: WordPress\PHPStan\StrictPathsIgnoreErrorExtension - arguments: - paths: %strictPaths% - tags: - - phpstan.ignoreErrorExtension - -parametersSchema: - strictPaths: listOf(string()) - parameters: # https://phpstan.org/user-guide/rule-levels level: 10 - # The two analyses share the cache of what PHPStan reads from each file, since both parse every file the same way, - # but each needs its own result cache. Its metadata includes the rule level, so a shared one would be discarded by - # every run of the other analysis. + # The two analyses share the cache of what PHPStan reads from each file, since both read every file the same way, + # but each needs its own result cache. Its metadata includes the rule level and the paths analyzed, so a shared one + # would be discarded by every run of the other analysis. resultCachePath: %tmpDir%/resultCache-level-10.php - # The errors outside the strict paths are dropped before the ignores are matched against them, so every - # `@phpstan-ignore` comment and baseline entry outside the strict paths would be reported as unmatched. Those are - # checked by phpstan.neon.dist instead. The entries of this configuration's own baselines each set - # `reportUnmatched: true`, which overrides this, so a stale one is still reported. - reportUnmatchedIgnoredErrors: false - - # The paths held to this rule level, relative to the repository root. A path ending in a slash is a directory, and - # covers every file below it. Any other path is a file. Each path must exist. + # The paths held to this rule level, replacing those analyzed by phpstan.neon.dist. A directory covers every file + # below it. # # Before adding a path, fix the errors this analysis reports in it, or baseline those that cannot be fixed yet. - strictPaths: + paths!: - src/wp-admin/includes/class-wp-filesystem-base.php - src/wp-admin/includes/class-wp-filesystem-direct.php - src/wp-admin/includes/class-wp-filesystem-ssh2.php - - src/wp-includes/abilities-api/ + - src/wp-includes/abilities-api - src/wp-includes/abilities-api.php - - src/wp-includes/ai-client/ + - src/wp-includes/ai-client - src/wp-includes/ai-client.php - src/wp-includes/class-wp-block-styles-registry.php - src/wp-includes/class-wp-block-template.php @@ -89,9 +72,29 @@ parameters: - src/wp-includes/html-api/class-wp-html-token.php - src/wp-includes/html-api/class-wp-html-unsupported-exception.php - src/wp-includes/l10n/class-wp-translations.php - - src/wp-includes/secrets/ + - src/wp-includes/secrets - src/wp-includes/secrets.php - src/wp-includes/sitemaps.php - src/wp-includes/speculative-loading.php - - src/wp-includes/style-engine/ - - tests/phpstan/ + - src/wp-includes/style-engine + - tests/phpstan + + # The code outside the strict paths that they can use. The bundled themes are left out, since nothing in core uses + # them. The files in the root are scanned for the constants they define, such as WPINC in wp-settings.php. + scanDirectories: + - src/wp-admin + - src/wp-includes + scanFiles: + - src/index.php + - src/wp-activate.php + - src/wp-blog-header.php + - src/wp-comments-post.php + - src/wp-cron.php + - src/wp-links-opml.php + - src/wp-load.php + - src/wp-login.php + - src/wp-mail.php + - src/wp-settings.php + - src/wp-signup.php + - src/wp-trackback.php + - src/xmlrpc.php diff --git a/tests/phpstan/StrictPathsIgnoreErrorExtension.php b/tests/phpstan/StrictPathsIgnoreErrorExtension.php deleted file mode 100644 index 6f648d89fd061..0000000000000 --- a/tests/phpstan/StrictPathsIgnoreErrorExtension.php +++ /dev/null @@ -1,114 +0,0 @@ - - */ - private array $directories = array(); - - /** - * Absolute paths of the individual files that are reported, as keys. - * - * @var array - */ - private array $files = array(); - - /** - * Constructor. - * - * @param string[] $paths Paths relative to the repository root. A path ending in a slash is a - * directory, which covers every file below it. Any other path is a file. - * - * @throws InvalidArgumentException When a path does not exist, so that a renamed or deleted path - * cannot silently stop being checked. - */ - public function __construct( array $paths ) { - $root = self::normalize( dirname( __DIR__, 2 ) ) . '/'; - - foreach ( $paths as $path ) { - $relative = ltrim( self::normalize( $path ), '/' ); - $absolute = $root . $relative; - - if ( str_ends_with( $relative, '/' ) ) { - if ( ! is_dir( $absolute ) ) { - throw new InvalidArgumentException( "The strict path \"$path\" is not a directory." ); - } - $this->directories[] = $absolute; - } else { - if ( ! is_file( $absolute ) ) { - throw new InvalidArgumentException( "The strict path \"$path\" is not a file. End it with a slash if it is a directory." ); - } - $this->files[ $absolute ] = true; - } - } - } - - /** - * Determines whether an error is outside the listed paths, and so ignored. - * - * The path checked is the file the code reported on is in, which for an error in a trait is - * the trait's file rather than that of the class using it. - * - * @param Error $error Error reported. - * @param Node $node Node the error was reported on. - * @param Scope $scope Scope of the node. - * @return bool Whether to ignore the error. - */ - public function shouldIgnore( Error $error, Node $node, Scope $scope ): bool { - $file = self::normalize( $error->getFilePath() ); - - if ( isset( $this->files[ $file ] ) ) { - return false; - } - - foreach ( $this->directories as $directory ) { - if ( str_starts_with( $file, $directory ) ) { - return false; - } - } - - return true; - } - - /** - * Normalizes the directory separators of a path to forward slashes. - * - * @param string $path Path. - * @return string Normalized path. - */ - private static function normalize( string $path ): string { - return str_replace( '\\', '/', $path ); - } -} diff --git a/tests/phpstan/base.neon b/tests/phpstan/base.neon index d62e1f2d039c9..1c102ca47e7da 100644 --- a/tests/phpstan/base.neon +++ b/tests/phpstan/base.neon @@ -305,7 +305,6 @@ parameters: - ApplyFiltersDynamicFunctionReturnTypeExtension.php - HookDocumentationRule.php - HookParamCountRule.php - - StrictPathsIgnoreErrorExtension.php bootstrapFiles: - bootstrap.php scanFiles: diff --git a/tests/phpstan/baselines-level-10/argument.type.neon b/tests/phpstan/baselines-level-10/argument.type.neon index 6958fdf80255c..61618d7556756 100644 --- a/tests/phpstan/baselines-level-10/argument.type.neon +++ b/tests/phpstan/baselines-level-10/argument.type.neon @@ -23,64 +23,53 @@ parameters: identifier: argument.type count: 1 path: ../../../src/wp-includes/abilities-api/class-wp-abilities-registry.php - reportUnmatched: true - message: '#^Parameter \#1 \$args of function wp_parse_args expects array\\|object\|string, mixed given\.$#' identifier: argument.type count: 2 path: ../../../src/wp-includes/abilities-api/class-wp-ability.php - reportUnmatched: true - message: '#^Parameter \#1 \$name of method WordPress\\AiClientDependencies\\Psr\\Http\\Message\\MessageInterface\:\:withHeader\(\) expects string, mixed given\.$#' identifier: argument.type count: 1 path: ../../../src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php - reportUnmatched: true - message: '#^Parameter \#1 \$wp_response of method WP_AI_Client_HTTP_Client\:\:create_psr_response\(\) expects array\, array given\.$#' identifier: argument.type count: 2 path: ../../../src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php - reportUnmatched: true - message: '#^Parameter \#2 \$value of method WordPress\\AiClientDependencies\\Psr\\Http\\Message\\MessageInterface\:\:withHeader\(\) expects array\\|string, mixed given\.$#' identifier: argument.type count: 1 path: ../../../src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php - reportUnmatched: true - message: '#^Parameter \#1 \$query of method wpdb\:\:query\(\) expects string, string\|null given\.$#' identifier: argument.type count: 1 path: ../../../src/wp-includes/secrets/class-wp-secrets-key-manager.php - reportUnmatched: true - message: '#^Parameter \#1 \$table of method wpdb\:\:delete\(\) expects string, string\|null given\.$#' identifier: argument.type count: 1 path: ../../../src/wp-includes/secrets/class-wp-secrets-key-manager.php - reportUnmatched: true - message: '#^Parameter \#1 \$table of method wpdb\:\:insert\(\) expects string, string\|null given\.$#' identifier: argument.type count: 1 path: ../../../src/wp-includes/secrets/class-wp-secrets-key-manager.php - reportUnmatched: true - message: '#^Parameter \#4 \$options of static method WP_Style_Engine_CSS_Declarations\:\:filter_declaration\(\) expects array\{important\?\: bool, \.\.\.\}, mixed given\.$#' identifier: argument.type count: 1 path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php - reportUnmatched: true - message: '#^Parameter \#3 \$options of method WP_Style_Engine_CSS_Declarations\:\:add_declaration\(\) expects array\{important\?\: bool, \.\.\.\}, mixed given\.$#' identifier: argument.type count: 1 path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-rule.php - reportUnmatched: true - message: '#^Parameter \#1 \$should_prettify of method WP_Style_Engine_CSS_Rule\:\:get_css\(\) expects bool, mixed given\.$#' identifier: argument.type count: 1 path: ../../../src/wp-includes/style-engine/class-wp-style-engine-processor.php - reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/cast.int.neon b/tests/phpstan/baselines-level-10/cast.int.neon index d5d3e96b43697..d2003cd002ba4 100644 --- a/tests/phpstan/baselines-level-10/cast.int.neon +++ b/tests/phpstan/baselines-level-10/cast.int.neon @@ -23,4 +23,3 @@ parameters: identifier: cast.int count: 1 path: ../../../src/wp-includes/class-wp-post.php - reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/method.notFound.neon b/tests/phpstan/baselines-level-10/method.notFound.neon index 84edfa07f6902..e9575f8ea0406 100644 --- a/tests/phpstan/baselines-level-10/method.notFound.neon +++ b/tests/phpstan/baselines-level-10/method.notFound.neon @@ -23,4 +23,3 @@ parameters: identifier: method.notFound count: 1 path: ../../../src/wp-includes/ai-client/class-wp-ai-client-builder.php - reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/missingType.iterableValue.neon b/tests/phpstan/baselines-level-10/missingType.iterableValue.neon index ed2de260b8754..05bdfc555dbac 100644 --- a/tests/phpstan/baselines-level-10/missingType.iterableValue.neon +++ b/tests/phpstan/baselines-level-10/missingType.iterableValue.neon @@ -23,40 +23,33 @@ parameters: identifier: missingType.iterableValue count: 1 path: ../../../src/wp-includes/abilities-api.php - reportUnmatched: true - message: '#^Function _wp_get_abilities_match_meta\(\) has parameter \$meta with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 path: ../../../src/wp-includes/abilities-api.php - reportUnmatched: true - message: '#^Function wp_get_abilities\(\) has parameter \$args with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 path: ../../../src/wp-includes/abilities-api.php - reportUnmatched: true - message: '#^Function wp_ai_client_embedding\(\) has parameter \$input with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 path: ../../../src/wp-includes/ai-client.php - reportUnmatched: true - message: '#^Function wp_ai_client_prompt\(\) has parameter \$prompt with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 path: ../../../src/wp-includes/ai-client.php - reportUnmatched: true - message: '#^Method WP_Style_Engine_CSS_Declarations\:\:get_declaration_options\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php - reportUnmatched: true - message: '#^Property WP_Style_Engine_CSS_Declarations\:\:\$declaration_options type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php - reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/missingType.return.neon b/tests/phpstan/baselines-level-10/missingType.return.neon index 77a2d175d3af6..b2320775c0ff9 100644 --- a/tests/phpstan/baselines-level-10/missingType.return.neon +++ b/tests/phpstan/baselines-level-10/missingType.return.neon @@ -23,22 +23,18 @@ parameters: identifier: missingType.return count: 1 path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php - reportUnmatched: true - message: '#^Method WP_Style_Engine_CSS_Rules_Store\:\:remove_rule\(\) has no return type specified\.$#' identifier: missingType.return count: 1 path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php - reportUnmatched: true - message: '#^Method WP_Style_Engine_CSS_Rules_Store\:\:set_name\(\) has no return type specified\.$#' identifier: missingType.return count: 1 path: ../../../src/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php - reportUnmatched: true - message: '#^Method WP_Style_Engine_Processor\:\:combine_rules_selectors\(\) has no return type specified\.$#' identifier: missingType.return count: 1 path: ../../../src/wp-includes/style-engine/class-wp-style-engine-processor.php - reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon b/tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon index 7f7d53f5dc74d..345bfe505a5f5 100644 --- a/tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon +++ b/tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon @@ -23,16 +23,13 @@ parameters: identifier: offsetAccess.nonOffsetAccessible count: 1 path: ../../../src/wp-includes/abilities-api/class-wp-ability.php - reportUnmatched: true - message: '#^Cannot access offset ''public'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible count: 1 path: ../../../src/wp-includes/abilities-api/class-wp-ability.php - reportUnmatched: true - message: '#^Cannot access offset ''show_in_rest'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible count: 1 path: ../../../src/wp-includes/abilities-api/class-wp-ability.php - reportUnmatched: true diff --git a/tests/phpstan/baselines-level-10/return.type.neon b/tests/phpstan/baselines-level-10/return.type.neon index 9d92f3ad04917..e4eab2aa7fc11 100644 --- a/tests/phpstan/baselines-level-10/return.type.neon +++ b/tests/phpstan/baselines-level-10/return.type.neon @@ -23,4 +23,3 @@ parameters: identifier: return.type count: 1 path: ../../../src/wp-includes/abilities-api/class-wp-ability-categories-registry.php - reportUnmatched: true diff --git a/tests/phpstan/generate-baselines.php b/tests/phpstan/generate-baselines.php index 86293bda0f3ed..3f91120f15b4d 100644 --- a/tests/phpstan/generate-baselines.php +++ b/tests/phpstan/generate-baselines.php @@ -400,15 +400,6 @@ static function () use ( $temp_config, $temp_baseline ): void { exit( 1 ); } -/* - * A configuration that turns off `reportUnmatchedIgnoredErrors` would also stop - * reporting the entries of its own baselines once they are stale, so each entry - * written for it turns that back on for itself. phpstan-level-10.neon.dist does - * so, because it drops the errors outside its strict paths before the ignores are - * matched against them. - */ -$report_unmatched = ! reports_unmatched_ignored_errors( $repo_root, $config_path, $memory_limit ); - /** * The entries of each error, grouped by the identifier of the error it suppresses. * @@ -430,7 +421,7 @@ static function () use ( $temp_config, $temp_baseline ): void { foreach ( $grouped as $entries ) { $all = array_merge( $all, $entries ); } - echo build_baseline( $all, $output_dir, "# Every identifier, combined.\n", $report_unmatched ); + echo build_baseline( $all, $output_dir, "# Every identifier, combined.\n" ); exit( 0 ); } @@ -481,7 +472,7 @@ static function () use ( $temp_config, $temp_baseline ): void { foreach ( $grouped as $identifier => $entries ) { $written = file_put_contents( $output_dir . '/' . $identifier . '.neon', - build_baseline( $entries, $output_dir, build_baseline_header( $identifier, $regenerate_options ), $report_unmatched ) + build_baseline( $entries, $output_dir, build_baseline_header( $identifier, $regenerate_options ) ) ); if ( false === $written ) { @@ -841,41 +832,6 @@ function count_errors( array $entries ): int { return $total; } -/** - * Determines whether a configuration reports ignores that no longer match an error. - * - * The parameter is read from what PHPStan resolves, so that it reflects every - * file the configuration includes. Only its line 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. - * - * @param non-empty-string $repo_root Absolute path to the repository root. - * @param non-empty-string $config_path Absolute path to the configuration file. - * @param string $memory_limit Memory limit passed to PHPStan. - * @return bool Whether `reportUnmatchedIgnoredErrors` is on. - */ -function reports_unmatched_ignored_errors( string $repo_root, string $config_path, string $memory_limit ): bool { - $command = sprintf( - '%s dump-parameters --configuration=%s --json --memory-limit=%s', - escapeshellarg( $repo_root . '/vendor/bin/phpstan' ), - escapeshellarg( $config_path ), - escapeshellarg( $memory_limit ) - ); - - $output = array(); - $exit_code = 0; - exec( $command, $output, $exit_code ); - - foreach ( $output as $line ) { - if ( 1 === preg_match( '/^\s*"reportUnmatchedIgnoredErrors": (true|false),?$/', $line, $matches ) ) { - return 'true' === $matches[1]; - } - } - - fwrite( STDERR, "Could not read reportUnmatchedIgnoredErrors from the configuration (exit status $exit_code).\n" ); - exit( 1 ); -} - /** * Builds a baseline file in PHPStan's NEON format. * @@ -883,14 +839,12 @@ function reports_unmatched_ignored_errors( string $repo_root, string $config_pat * be diffed against one it produced. Paths are rewritten relative to the file's * own directory, since that is what a NEON `path` resolves against. * - * @param list, path: non-empty-string}> $entries Baseline entries. - * @param non-empty-string $output_dir Directory the file is written to. - * @param string $header Comment block, or an empty string. - * @param bool $report_unmatched Whether each entry sets `reportUnmatched: true`, for a - * configuration that does not report unmatched ignores. + * @param list, path: non-empty-string}> $entries Baseline entries. + * @param non-empty-string $output_dir Directory the file is written to. + * @param string $header Comment block, or an empty string. * @return non-falsy-string Baseline file contents. */ -function build_baseline( array $entries, string $output_dir, string $header, bool $report_unmatched ): string { +function build_baseline( array $entries, string $output_dir, string $header ): string { $contents = ( '' === $header ? '' : $header . "\n" ) . "parameters:\n\tignoreErrors:\n"; foreach ( $entries as $entry ) { @@ -898,8 +852,7 @@ function build_baseline( array $entries, string $output_dir, string $header, boo . "\t\t\tmessage: " . quote_neon_value( $entry['message'] ) . "\n" . "\t\t\tidentifier: " . $entry['identifier'] . "\n" . "\t\t\tcount: " . $entry['count'] . "\n" - . "\t\t\tpath: " . get_relative_path( $output_dir, $entry['path'] ) . "\n" - . ( $report_unmatched ? "\t\t\treportUnmatched: true\n" : '' ); + . "\t\t\tpath: " . get_relative_path( $output_dir, $entry['path'] ) . "\n"; } return $contents; From e3767ebafc55f275bd78687abe69f7f0460d32d8 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 15 Nov 2026 20:44:59 -0800 Subject: [PATCH 06/30] Build/Test Tools: Document the level 10 PHPStan analysis. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- phpstan.neon.dist | 3 +++ tests/phpstan/README.md | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 260afa934953f..421aef0b7757c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,8 @@ # PHPStan configuration for WordPress Core. # +# This analyzes the whole codebase. phpstan-level-10.neon.dist includes it, and holds selected +# paths to a stricter rule level. `composer phpstan` runs both. +# # To override this configuration, create a phpstan.neon which includes this file and adjusts # its parameters as needed, rather than copying it, so that the copy does not go stale. See # tests/phpstan/README.md for examples. diff --git a/tests/phpstan/README.md b/tests/phpstan/README.md index 7dd1df431d4a9..a896f091b58f5 100644 --- a/tests/phpstan/README.md +++ b/tests/phpstan/README.md @@ -16,6 +16,8 @@ npm run typecheck:php which will run PHPStan in the Docker container. +This runs two analyses, one after the other: the whole codebase with [`phpstan.neon.dist`](../../phpstan.neon.dist), and then the paths held to a stricter rule level with [`phpstan-level-10.neon.dist`](../../phpstan-level-10.neon.dist), as described in [Stricter analysis of selected paths](#stricter-analysis-of-selected-paths). The command fails when either of them reports an error. + Additional flags supported by PHPStan can be passed by passing `--` followed by the flags themselves. For example, ```bash @@ -41,14 +43,16 @@ composer run phpstan -- -vvv --debug Note the `--` in each of those. Composer needs it in order to pass the flags on to PHPStan rather than reading them as its own, and without it they are discarded silently. The npm script supplies it, which is why only one is needed there. +The flags are passed to both analyses. To run only one of them, as CI does, use `composer phpstan:level-5` or `composer phpstan:level-10`, or name a configuration with `--configuration`. + For available flags, see https://phpstan.org/user-guide/command-line-usage. ## Results on pull requests -The analysis also runs on every pull request that changes PHP files or the PHPStan configuration. The errors it reports are shown in two places: +Both analyses also run on every pull request that changes PHP files or the PHPStan configuration, as two jobs. The errors they report are shown in two places: - As annotations on the changed files. Most errors are annotated as warnings, which do not fail the check. -- In a comment on the pull request, which lists every error in a table along with the commit it was first reported for. The comment is updated as new commits are pushed, moving each error that a commit resolves into a collapsed list of resolved errors, which also names that commit. Once all of the errors are resolved, the comment is marked as resolved and collapsed. +- In a comment on the pull request, which lists every error in a table along with the commit it was first reported for. The comment is updated as new commits are pushed, moving each error that a commit resolves into a collapsed list of resolved errors, which also names that commit. Once all of the errors are resolved, the comment is marked as resolved and collapsed. The comment combines both analyses: an error reported by both is listed once, and when an error is only reported at level 10, the table gains a Level column saying so. Some errors cannot be ignored, and so cannot be reported as warnings either. These fail the check. The most common is an [out-of-date baseline](#removing-stale-entries-with---fix), which is reported when an error recorded in a baseline was fixed without the baseline being updated. Such an error is reported against a file rather than a line in it, so its annotation does not appear alongside the changes, and it would easily go unnoticed if the check passed. @@ -104,6 +108,24 @@ parameters: ignoreErrors!: [] ``` +### Stricter analysis of selected paths + +`phpstan.neon.dist` holds the whole codebase to a low rule level, since most of it does not yet meet a higher one. Some of it already does, mostly code added in recent releases, such as the Secrets API, the AI client, and the Abilities API. [`phpstan-level-10.neon.dist`](../../phpstan-level-10.neon.dist) holds those paths to rule level 10, so that they keep meeting it. + +It includes `phpstan.neon.dist`, so everything that enforces still applies, and replaces the paths analyzed with the ones it lists under `paths!`. The rest of core is scanned instead, so that what those paths use is known. A scanned file gets the same [WordPress-specific extensions](#wordpress-specific-extensions) as an analyzed one, because `base.neon` has every parse run them, so the types of the code outside the strict paths are the same as in the analysis of the whole codebase. + +Errors are baselined in two layers. An error that the analysis of the whole codebase reports is baselined in [`baselines/`](baselines), as usual, and stays baselined there for the level 10 analysis. What level 10 adds in the strict paths is baselined in [`baselines-level-10/`](baselines-level-10), in the same way, and included through its own [`loader.php`](baselines-level-10/loader.php). `composer phpstan:baselines` and `composer phpstan:fix` maintain both. + +To hold another path to level 10: + +1. Add it to `paths!` in `phpstan-level-10.neon.dist`. +2. Run `composer phpstan:level-10`, and fix the errors it reports. +3. Baseline any that cannot be fixed yet with `composer phpstan:baselines`. + +In the strict paths, **do not add an `@phpstan-ignore` comment for an error that only levels 6 to 10 report**. The analysis of the whole codebase does not report that error, so it reports the comment as ignoring nothing, and `composer phpstan:fix` would remove it. Fix the error, or baseline it instead. + +A local `phpstan-level-10.neon` overrides `phpstan-level-10.neon.dist`, the same way `phpstan.neon` overrides `phpstan.neon.dist`. When a local `phpstan.neon` already analyzes everything at level 10, `composer phpstan` skips the second analysis, since it could only repeat part of the first. + For more information about configuring PHPStan, see the [PHPStan documentation's Config reference](https://phpstan.org/config-reference). ## WordPress-specific extensions @@ -234,16 +256,15 @@ or, outside the Docker environment: composer phpstan:fix ``` -This runs three steps, each only when the one before it succeeds: +This runs three steps: -1. PHPStan with its `--fix` option, which lowers the count of the entry, or removes the entry, leaving the rest of the baseline as it was. It is usually much faster than regenerating, since it reuses the result cache of the run that reported the errors. Unlike regenerating, it also removes an `@phpstan-ignore` comment that no longer matches. +1. PHPStan with its `--fix` option, once with `phpstan.neon.dist` and once with `phpstan-level-10.neon.dist`. It lowers the count of the entry, or removes the entry, leaving the rest of the baseline as it was. It is usually much faster than regenerating, since it reuses the result cache of the run that reported the errors. Unlike regenerating, it also removes an `@phpstan-ignore` comment that no longer matches. PHPStan says `No fixable errors found` for a configuration with nothing to fix, which does not stop the other steps. 2. `composer phpstan:baselines -- --prune`, which deletes any baseline left with no entries. Removing the last entry of a baseline leaves the file behind, as `ignoreErrors: []`. Pruning analyzes nothing, so it can also be run on its own. -3. The analysis once more, which reuses the result cache and so is quick. PHPStan's `--fix` reports only what it fixed, and succeeds even when other errors remain, so this is what shows the errors that are left. +3. Both analyses once more, which reuse the result cache and so are quick. PHPStan's `--fix` reports only what it fixed, and succeeds even when other errors remain, so this is what shows the errors that are left. Keep in mind: -- **It fails when nothing is fixable.** PHPStan then says `No fixable errors found` and stops the script there, so run `composer phpstan` to see whether any errors remain. -- **It always analyzes the whole tree with `phpstan.neon.dist`**, whatever a local `phpstan.neon` says. PHPStan only reports stale ignores when it analyzes every path, and a configuration at another rule level can report a baselined error with a different message, in which case `--fix` would remove an entry that the default configuration still needs. +- **It always analyzes with the two `.dist` configurations**, whatever a local `phpstan.neon` or `phpstan-level-10.neon` says. A configuration at another rule level can report a baselined error with a different message, in which case `--fix` would remove an entry that the default configuration still needs. - **It fixes every fixable error the run reports**, not only stale ignores. A few other errors can also be fixed automatically, such as a [useless cast](https://phpstan.org/error-identifiers/cast.useless), so check the diff before committing it. - PHPStan's `--fix-ignored`, run as `composer phpstan -- --fix-ignored`, goes further and also fixes the fixable errors which a baseline currently ignores. That is a way to work through a baseline, but expect larger diffs, and follow it with `composer phpstan:baselines -- --prune`. @@ -294,6 +315,8 @@ Note the `--` in each of those. Composer needs it in order to pass the flags on A run also deletes any baseline whose identifier no longer reports anything. Since the baselines are included through [`baselines/loader.php`](baselines/loader.php), adding a newly split out baseline, and retiring one that has reached zero, need no edit of the configuration. +Each run regenerates both sets of baselines: those of `phpstan.neon.dist` in [`baselines/`](baselines), and then those of `phpstan-level-10.neon.dist` in [`baselines-level-10/`](baselines-level-10). The order matters, since the level 10 configuration includes the other one along with its baselines, so its own are only what is left over. The options apply to both, except `--combined`, which only prints the baseline of `phpstan.neon.dist`. To regenerate one set, name its configuration with `--config`, such as `--config=phpstan-level-10.neon.dist`. + PHPStan's own `--generate-baseline` is deliberately not used directly. It captures every error a run reports, with no way to restrict it to one identifier, so it cannot refresh a single baseline without sweeping every other kind of error into it. ## Performance and troubleshooting From d444fe349274b6b7ca693d1e86ea08bec26cdd3d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 15 Nov 2026 21:08:58 -0800 Subject: [PATCH 07/30] Build/Test Tools: Run a single PHPStan analysis for single-analysis arguments. `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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/analyse.php | 96 ++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 17 deletions(-) diff --git a/tests/phpstan/analyse.php b/tests/phpstan/analyse.php index 21499d5493d46..eaf5cc2cdfc11 100644 --- a/tests/phpstan/analyse.php +++ b/tests/phpstan/analyse.php @@ -23,8 +23,10 @@ * baselines left without entries are then deleted, and both analyses run again * to show what remains. * - * Every other argument is passed to each analysis. Naming a configuration with - * `--configuration` or `-c` runs only that one, as PHPStan itself would. + * Every other argument is passed to each analysis, except that an argument which + * only makes sense for one, such as paths to analyze, a configuration, a level, or + * a report format for a program to read, runs only the first, as PHPStan itself + * would. * * Run it through Composer: * @@ -69,14 +71,23 @@ $args = array_values( array_diff( $args, array( '--fix' ) ) ); } -foreach ( $args as $arg ) { - if ( '-c' === $arg || str_starts_with( $arg, '--configuration' ) || ( str_starts_with( $arg, '-c' ) && ! str_starts_with( $arg, '--' ) ) ) { - if ( $fix ) { - fwrite( STDERR, "--fix always uses the default configurations, so it cannot be combined with --configuration.\n" ); - exit( 1 ); - } - exit( run( 'Analyzing with the configuration given', $phpstan, $args ) ); +/* + * Some arguments only make sense for a single analysis. Paths would replace the + * strict paths of the second one, holding whatever they name to level 10; a level + * would analyze the strict paths at another; a report format meant to be read by + * a program would print two reports in a row; and a baseline would be written by + * each in turn. With any of them, only the first analysis runs, as it did before + * there were two. + */ +$single_reason = get_single_analysis_reason( $args ); + +if ( null !== $single_reason ) { + if ( $fix ) { + fwrite( STDERR, "--fix always uses the default configurations and every path, so it cannot be combined with $single_reason.\n" ); + exit( 1 ); } + fwrite( STDERR, "Running a single analysis, because of $single_reason.\n" ); + exit( run( 'Analyzing', $phpstan, $args ) ); } if ( $fix ) { @@ -89,7 +100,7 @@ } } - $status = run( 'Deleting the baselines left without entries', PHP_BINARY, array( __DIR__ . '/generate-baselines.php', '--prune' ), false ); + $status = run( 'Deleting the baselines left without entries', __DIR__ . '/generate-baselines.php', array( '--prune' ), false ); if ( 0 !== $status ) { exit( $status ); } @@ -120,16 +131,19 @@ * The heading goes to stderr, so that what the command writes to stdout, such as * a report in a machine-readable format, is left as it is. * + * The script runs on the PHP running this one, which Composer's `@php` chose, + * rather than on whichever `php` the script's shebang finds first. + * * @param string $heading Heading describing the run. - * @param string $command Command to run. - * @param string[] $args Arguments, each escaped for the shell. - * @param bool $is_analysis Whether the command is a PHPStan analysis, to which `analyse` is passed first. - * @return int Exit status of the command. + * @param string $script Path to the PHP script to run. + * @param string[] $args Arguments, which are escaped for the shell here. + * @param bool $is_analysis Whether the script is PHPStan, to which `analyse` is passed first. + * @return int Exit status of the script. */ -function run( string $heading, string $command, array $args, bool $is_analysis = true ): int { +function run( string $heading, string $script, array $args, bool $is_analysis = true ): int { fwrite( STDERR, "\n== $heading ==\n\n" ); - $parts = array( escapeshellarg( $command ) ); + $parts = array( escapeshellarg( PHP_BINARY ), escapeshellarg( $script ) ); if ( $is_analysis ) { $parts[] = 'analyse'; } @@ -157,7 +171,7 @@ function run( string $heading, string $command, array $args, bool $is_analysis = function is_strictest_level( string $phpstan, string $config ): bool { $output = array(); $exit_code = 0; - exec( sprintf( '%s dump-parameters --configuration=%s --json 2>/dev/null', escapeshellarg( $phpstan ), escapeshellarg( $config ) ), $output, $exit_code ); + exec( sprintf( '%s %s dump-parameters --configuration=%s --json 2>/dev/null', escapeshellarg( PHP_BINARY ), escapeshellarg( $phpstan ), escapeshellarg( $config ) ), $output, $exit_code ); foreach ( $output as $line ) { if ( 1 === preg_match( '/^\s*"level": ("max"|"?\d+"?),?$/', $line, $matches ) ) { @@ -168,3 +182,51 @@ function is_strictest_level( string $phpstan, string $config ): bool { return false; } + +/** + * Finds an argument that only makes sense for a single analysis. + * + * Those are a configuration, a level, a report format, a baseline to generate, + * `--fix-ignored`, and the paths to analyze. An option's value can follow it as the + * next argument, so that is skipped rather than taken for a path. + * + * @param string[] $args Arguments. + * @return string|null Description of the first such argument, or null if there is none. + */ +function get_single_analysis_reason( array $args ): ?string { + // The options whose value can be given as the next argument rather than after `=`. + $takes_value = array( '-c', '--configuration', '-l', '--level', '-a', '--autoload-file', '--error-format', '--memory-limit', '--tmp-file', '--instead-of' ); + $single = array( '-c', '--configuration', '-l', '--level', '--error-format', '--generate-baseline', '-b', '--fix-ignored' ); + + $count = count( $args ); + for ( $i = 0; $i < $count; $i++ ) { + $arg = $args[ $i ]; + + if ( '--' === $arg ) { + return $i + 1 < $count ? 'the paths given' : null; + } + + if ( '' === $arg || '-' !== $arg[0] ) { + return 'the paths given'; + } + + // A long option's value follows `=`, and a short option's follows its letter directly, as in `-l6`. + if ( 0 === strpos( $arg, '--' ) ) { + $name = explode( '=', $arg, 2 )[0]; + $has_value = false !== strpos( $arg, '=' ); + } else { + $name = substr( $arg, 0, 2 ); + $has_value = strlen( $arg ) > 2; + } + + if ( in_array( $name, $single, true ) ) { + return $name; + } + + if ( ! $has_value && in_array( $name, $takes_value, true ) ) { + ++$i; + } + } + + return null; +} From 79bd33fa0ee3c66c69c877b9600447549f5fc0a3 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 18:43:46 -0800 Subject: [PATCH 08/30] Build/Test Tools: Write a local PHPStan override's baselines to its own 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/generate-baselines.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/phpstan/generate-baselines.php b/tests/phpstan/generate-baselines.php index 3f91120f15b4d..29aef9e860380 100644 --- a/tests/phpstan/generate-baselines.php +++ b/tests/phpstan/generate-baselines.php @@ -194,10 +194,17 @@ /* * A default configuration named without an output directory writes to its own, * so that naming phpstan-level-10.neon.dist alone cannot write its baselines over - * those of phpstan.neon.dist. + * those of phpstan.neon.dist. So does a local override of one, such as + * phpstan-level-10.neon, named as the `.dist` file is but without the suffix. + * Written to the default directory instead, the level 10 analysis of only the + * strict paths, with the baselines there suppressed, would retire every baseline of + * the whole codebase it does not report again. */ +$config_relative = trim( normalize_path( $config_option ), '/' ); +$config_output_dir = DEFAULT_CONFIGS[ $config_relative ] ?? DEFAULT_CONFIGS[ $config_relative . '.dist' ] ?? DEFAULT_OUTPUT_DIR; + if ( null === $output_option ) { - $output_option = DEFAULT_CONFIGS[ trim( normalize_path( $config_option ), '/' ) ] ?? DEFAULT_OUTPUT_DIR; + $output_option = $config_output_dir; } $config_path = $repo_root . '/' . ltrim( $config_option, '/' ); @@ -320,8 +327,6 @@ static function () use ( $temp_config, $temp_baseline ): void { * readings of everything it does not cover. Keying the directory on the * configuration keeps each one's reflection to itself. */ -$config_relative = trim( normalize_path( $config_option ), '/' ); - if ( DEFAULT_CONFIG !== $config_relative ) { $analysis_tmp_dir .= '-' . (string) preg_replace( '/[^A-Za-z0-9._]+/', '-', $config_relative ); } @@ -465,7 +470,7 @@ static function () use ( $temp_config, $temp_baseline ): void { if ( DEFAULT_CONFIG !== $config_relative ) { $regenerate_options .= ' --config=' . $config_option; } -if ( ( DEFAULT_CONFIGS[ $config_relative ] ?? DEFAULT_OUTPUT_DIR ) !== trim( normalize_path( $output_option ), '/' ) ) { +if ( $config_output_dir !== trim( normalize_path( $output_option ), '/' ) ) { $regenerate_options .= ' --output-dir=' . $output_option; } @@ -555,7 +560,8 @@ function get_usage(): string { in other directories stay in force, so only the errors they leave are written. Default: the directory of the configuration named - above, or else tests/phpstan/baselines + above, or of the one it overrides locally, such as + phpstan-level-10.neon, or else tests/phpstan/baselines --combined Print one combined baseline to stdout instead of writing per-identifier files. Nothing is written to disk. Only phpstan.neon.dist is analyzed, unless --config names From a2a08fff9dda6d5cc5f63eb5f6f713d72eb53ca2 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 15 Nov 2026 21:09:34 -0800 Subject: [PATCH 09/30] Build/Test Tools: Point to the right job for PHPStan errors left out of the comment. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- .github/workflows/phpstan-pull-request-comments.yml | 5 ++++- .github/workflows/reusable-phpstan-static-analysis-v1.yml | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/phpstan-pull-request-comments.yml b/.github/workflows/phpstan-pull-request-comments.yml index 32f647bf561b3..d934253193b25 100644 --- a/.github/workflows/phpstan-pull-request-comments.yml +++ b/.github/workflows/phpstan-pull-request-comments.yml @@ -262,7 +262,10 @@ jobs: // GitHub shows only the first few annotations of each kind from a step on the page of the workflow run, so // errors left out of a table are pointed to in the log of the step that reported them, which has them all. - const where = `the log of the [workflow run](${ run.html_url }), in the “Report the analysis results” step`; + // Each analysis runs in a job of its own, and an error found only at level 10 is only in that job's log. + const where = level10Only.length > 0 + ? `the log of the [workflow run](${ run.html_url }), in the “Report the analysis results” step of each of its jobs (level 10 errors are only in the “level 10 paths” job)` + : `the log of the [workflow run](${ run.html_url }), in the “Report the analysis results” step`; const table = ( rows, rowLimit, { withResolution = false } = {} ) => { const shown = rows.slice( 0, rowLimit ); if ( shown.length === 0 ) { diff --git a/.github/workflows/reusable-phpstan-static-analysis-v1.yml b/.github/workflows/reusable-phpstan-static-analysis-v1.yml index d3ae7b16cf553..cdcbe01d1cd43 100644 --- a/.github/workflows/reusable-phpstan-static-analysis-v1.yml +++ b/.github/workflows/reusable-phpstan-static-analysis-v1.yml @@ -236,6 +236,7 @@ jobs: fs.writeFileSync( `${ process.env.RUNNER_TEMP }/phpstan-results/results.json`, JSON.stringify( { pull_request: context.payload.pull_request.number, analysis, + // Keep this list in step with the `analysis` values of the job's matrix. ...( analysis === 'level-5' ? { analyses: [ 'level-5', 'level-10' ] } : {} ), changed_in_base: changedInBase, errors: errors.map( ( { tip, fixable, ...error } ) => error ), From af6e512adc74861714dfe1557e66a5e6997bb986 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 15 Nov 2026 21:09:51 -0800 Subject: [PATCH 10/30] Build/Test Tools: Clarify running one PHPStan analysis and adding a strict 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/phpstan/README.md b/tests/phpstan/README.md index a896f091b58f5..04c828dd83d0a 100644 --- a/tests/phpstan/README.md +++ b/tests/phpstan/README.md @@ -43,7 +43,7 @@ composer run phpstan -- -vvv --debug Note the `--` in each of those. Composer needs it in order to pass the flags on to PHPStan rather than reading them as its own, and without it they are discarded silently. The npm script supplies it, which is why only one is needed there. -The flags are passed to both analyses. To run only one of them, as CI does, use `composer phpstan:level-5` or `composer phpstan:level-10`, or name a configuration with `--configuration`. +The flags are passed to both analyses, except that paths, `--configuration`, `--level`, `--error-format`, `--generate-baseline`, and `--fix-ignored` run only the first, since each only makes sense for one. To run only one of them, as CI does, use `composer phpstan:level-5` or `composer phpstan:level-10`. Those always use the `.dist` configurations, ignoring a local override. For available flags, see https://phpstan.org/user-guide/command-line-usage. @@ -118,9 +118,10 @@ Errors are baselined in two layers. An error that the analysis of the whole code To hold another path to level 10: -1. Add it to `paths!` in `phpstan-level-10.neon.dist`. -2. Run `composer phpstan:level-10`, and fix the errors it reports. -3. Baseline any that cannot be fixed yet with `composer phpstan:baselines`. +1. Make sure no entry in [`baselines/`](baselines) is for a file in the path. Both analyses enforce those entries, but each may report a different number of the errors one ignores, and then no count satisfies both. Fix those errors first. +2. Add the path to `paths!` in `phpstan-level-10.neon.dist`. +3. Run `composer phpstan:level-10`, and fix the errors it reports. +4. Baseline any that cannot be fixed yet with `composer phpstan:baselines`. In the strict paths, **do not add an `@phpstan-ignore` comment for an error that only levels 6 to 10 report**. The analysis of the whole codebase does not report that error, so it reports the comment as ignoring nothing, and `composer phpstan:fix` would remove it. Fix the error, or baseline it instead. From d02ce9792e6837449e589315bf0e9a1f298c8635 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 18:45:15 -0800 Subject: [PATCH 11/30] Build/Test Tools: Stop holding the reverted Secrets API to PHPStan level 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- phpstan-level-10.neon.dist | 2 -- .../phpstan/baselines-level-10/argument.type.neon | 15 --------------- 2 files changed, 17 deletions(-) diff --git a/phpstan-level-10.neon.dist b/phpstan-level-10.neon.dist index 21b43d4ce740f..778eed54a0dca 100644 --- a/phpstan-level-10.neon.dist +++ b/phpstan-level-10.neon.dist @@ -72,8 +72,6 @@ parameters: - src/wp-includes/html-api/class-wp-html-token.php - src/wp-includes/html-api/class-wp-html-unsupported-exception.php - src/wp-includes/l10n/class-wp-translations.php - - src/wp-includes/secrets - - src/wp-includes/secrets.php - src/wp-includes/sitemaps.php - src/wp-includes/speculative-loading.php - src/wp-includes/style-engine diff --git a/tests/phpstan/baselines-level-10/argument.type.neon b/tests/phpstan/baselines-level-10/argument.type.neon index 61618d7556756..fe58aa3d9dcfd 100644 --- a/tests/phpstan/baselines-level-10/argument.type.neon +++ b/tests/phpstan/baselines-level-10/argument.type.neon @@ -43,21 +43,6 @@ parameters: identifier: argument.type count: 1 path: ../../../src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php - - - message: '#^Parameter \#1 \$query of method wpdb\:\:query\(\) expects string, string\|null given\.$#' - identifier: argument.type - count: 1 - path: ../../../src/wp-includes/secrets/class-wp-secrets-key-manager.php - - - message: '#^Parameter \#1 \$table of method wpdb\:\:delete\(\) expects string, string\|null given\.$#' - identifier: argument.type - count: 1 - path: ../../../src/wp-includes/secrets/class-wp-secrets-key-manager.php - - - message: '#^Parameter \#1 \$table of method wpdb\:\:insert\(\) expects string, string\|null given\.$#' - identifier: argument.type - count: 1 - path: ../../../src/wp-includes/secrets/class-wp-secrets-key-manager.php - message: '#^Parameter \#4 \$options of static method WP_Style_Engine_CSS_Declarations\:\:filter_declaration\(\) expects array\{important\?\: bool, \.\.\.\}, mixed given\.$#' identifier: argument.type From aec7d489c1a2fe95038360c6bb5354aa39119536 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 18:45:36 -0800 Subject: [PATCH 12/30] Build/Test Tools: Stop naming the Secrets API among the level 10 paths. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpstan/README.md b/tests/phpstan/README.md index 04c828dd83d0a..5ba4d8a3b5ec3 100644 --- a/tests/phpstan/README.md +++ b/tests/phpstan/README.md @@ -110,7 +110,7 @@ parameters: ### Stricter analysis of selected paths -`phpstan.neon.dist` holds the whole codebase to a low rule level, since most of it does not yet meet a higher one. Some of it already does, mostly code added in recent releases, such as the Secrets API, the AI client, and the Abilities API. [`phpstan-level-10.neon.dist`](../../phpstan-level-10.neon.dist) holds those paths to rule level 10, so that they keep meeting it. +`phpstan.neon.dist` holds the whole codebase to a low rule level, since most of it does not yet meet a higher one. Some of it already does, mostly code added in recent releases, such as the AI client and the Abilities API. [`phpstan-level-10.neon.dist`](../../phpstan-level-10.neon.dist) holds those paths to rule level 10, so that they keep meeting it. It includes `phpstan.neon.dist`, so everything that enforces still applies, and replaces the paths analyzed with the ones it lists under `paths!`. The rest of core is scanned instead, so that what those paths use is known. A scanned file gets the same [WordPress-specific extensions](#wordpress-specific-extensions) as an analyzed one, because `base.neon` has every parse run them, so the types of the code outside the strict paths are the same as in the analysis of the whole codebase. From 71f3ec7b731a3f03d40d57bacc4003692dee7a33 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 18:46:01 -0800 Subject: [PATCH 13/30] Build/Test Tools: Include the level 10 PHPStan baselines through a loader. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- phpstan-level-10.neon.dist | 14 +++----------- .../baselines-level-10/argument.type.neon | 8 ++++---- tests/phpstan/baselines-level-10/cast.int.neon | 8 ++++---- tests/phpstan/baselines-level-10/loader.php | 16 ++++++++++++++++ .../baselines-level-10/method.notFound.neon | 8 ++++---- .../missingType.iterableValue.neon | 8 ++++---- .../baselines-level-10/missingType.return.neon | 8 ++++---- .../offsetAccess.nonOffsetAccessible.neon | 8 ++++---- .../phpstan/baselines-level-10/return.type.neon | 8 ++++---- 9 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 tests/phpstan/baselines-level-10/loader.php diff --git a/phpstan-level-10.neon.dist b/phpstan-level-10.neon.dist index 778eed54a0dca..6a7f319dae129 100644 --- a/phpstan-level-10.neon.dist +++ b/phpstan-level-10.neon.dist @@ -22,17 +22,9 @@ includes: - phpstan.neon.dist # Preexisting errors at this level in the strict paths, beyond those baselined by phpstan.neon.dist. They are - # organized and regenerated the same way, by `composer phpstan:baselines`, which rewrites both the files and the - # list between the markers. Do not edit that list by hand. - # phpstan:baselines start - - tests/phpstan/baselines-level-10/argument.type.neon - - tests/phpstan/baselines-level-10/cast.int.neon - - tests/phpstan/baselines-level-10/method.notFound.neon - - tests/phpstan/baselines-level-10/missingType.iterableValue.neon - - tests/phpstan/baselines-level-10/missingType.return.neon - - tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon - - tests/phpstan/baselines-level-10/return.type.neon - # phpstan:baselines end + # organized and regenerated the same way, by `composer phpstan:baselines`, and included the same way, through the + # loader in their directory. + - tests/phpstan/baselines-level-10/loader.php parameters: # https://phpstan.org/user-guide/rule-levels diff --git a/tests/phpstan/baselines-level-10/argument.type.neon b/tests/phpstan/baselines-level-10/argument.type.neon index fe58aa3d9dcfd..ab4a4096ee3d9 100644 --- a/tests/phpstan/baselines-level-10/argument.type.neon +++ b/tests/phpstan/baselines-level-10/argument.type.neon @@ -7,14 +7,14 @@ # silently. Fixing an occurrence therefore means decrementing or removing its # entry here as part of the same change. # -# The goal is to empty this file and delete it, along with the `includes` entry -# for it in phpstan-level-10.neon.dist. +# The goal is to empty this file and delete it. # # Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with # -# composer phpstan:baselines -- --identifier=argument.type +# composer phpstan:baselines -- --identifier=argument.type --config=phpstan-level-10.neon.dist # -# which reruns the analysis with this file suppressed so the errors surface again. +# which reruns the analysis with the baselines in this directory suppressed, so +# that their errors surface again, and rewrites only this file. parameters: ignoreErrors: diff --git a/tests/phpstan/baselines-level-10/cast.int.neon b/tests/phpstan/baselines-level-10/cast.int.neon index d2003cd002ba4..6c499dbf87337 100644 --- a/tests/phpstan/baselines-level-10/cast.int.neon +++ b/tests/phpstan/baselines-level-10/cast.int.neon @@ -7,14 +7,14 @@ # silently. Fixing an occurrence therefore means decrementing or removing its # entry here as part of the same change. # -# The goal is to empty this file and delete it, along with the `includes` entry -# for it in phpstan-level-10.neon.dist. +# The goal is to empty this file and delete it. # # Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with # -# composer phpstan:baselines -- --identifier=cast.int +# composer phpstan:baselines -- --identifier=cast.int --config=phpstan-level-10.neon.dist # -# which reruns the analysis with this file suppressed so the errors surface again. +# which reruns the analysis with the baselines in this directory suppressed, so +# that their errors surface again, and rewrites only this file. parameters: ignoreErrors: diff --git a/tests/phpstan/baselines-level-10/loader.php b/tests/phpstan/baselines-level-10/loader.php new file mode 100644 index 0000000000000..829e4ac4880d4 --- /dev/null +++ b/tests/phpstan/baselines-level-10/loader.php @@ -0,0 +1,16 @@ + Date: Tue, 17 Nov 2026 18:55:54 -0800 Subject: [PATCH 14/30] Build/Test Tools: Write a PHPStan baselines loader before the analysis. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/generate-baselines.php | 74 ++++++++++++++++------------ 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/tests/phpstan/generate-baselines.php b/tests/phpstan/generate-baselines.php index 29aef9e860380..dfad8bb14ef63 100644 --- a/tests/phpstan/generate-baselines.php +++ b/tests/phpstan/generate-baselines.php @@ -368,12 +368,53 @@ static function () use ( $temp_config, $temp_baseline ): void { escapeshellarg( $memory_limit ) ); +/* + * The baselines only take effect through a loader in their own directory. It is + * written on every run, so that the committed loader of the default directory, and + * that of any other, stay what build_loader() makes rather than drifting from it + * unnoticed. A directory given with `--output-dir` that had none is not included + * by anything yet, so say so. + * + * It is written before the analysis rather than after, since a configuration may + * already include it, and PHPStan refuses to run with an include that is missing. + * That is how the baselines of a new configuration are first generated: add the + * loader of its directory to its `includes`, then run this with `--config` and + * `--output-dir` naming them. With the directory suppressed, the loader includes + * nothing during the analysis either way. + * + * `--combined` writes nothing to disk, so a missing loader stays missing then. + */ +if ( ! $combined ) { + if ( ! is_dir( $output_dir ) && ! mkdir( $output_dir, 0755, true ) ) { + fwrite( STDERR, "Could not create $output_option\n" ); + exit( 1 ); + } + + $loader_path = $output_dir . '/loader.php'; + $loader = build_loader( $output_dir ); + $loader_existed = is_file( $loader_path ); + $loader_contents = $loader_existed ? file_get_contents( $loader_path ) : false; + + if ( $loader !== $loader_contents ) { + if ( false === file_put_contents( $loader_path, $loader ) ) { + fwrite( STDERR, "Could not write $output_option/loader.php\n" ); + exit( 1 ); + } + + printf( + $loader_existed ? "%s: rewritten.\n" : "%s: written. The configuration has to include it for these baselines to take effect.\n", + $output_option . '/loader.php' + ); + } +} + fwrite( STDERR, "Analyzing with $config_option, baselines in $output_option suppressed...\n" ); /* * PHPStan inherits it, as do the worker processes it starts. It is the real path, - * since that is what the loader's __DIR__ is. An output directory not created yet - * holds no loader to match, so it is not set at all then. It is cleared first + * since that is what the loader's __DIR__ is. An output directory that does not + * exist, which only `--combined` leaves uncreated, holds no loader to match, so it + * is not set at all then. It is cleared first * either way, so that a value exported in the shell, perhaps naming another * directory, cannot switch off baselines this run means to keep. */ @@ -430,35 +471,6 @@ static function () use ( $temp_config, $temp_baseline ): void { exit( 0 ); } -if ( ! is_dir( $output_dir ) && ! mkdir( $output_dir, 0755, true ) ) { - fwrite( STDERR, "Could not create $output_option\n" ); - exit( 1 ); -} - -/* - * The baselines only take effect through a loader in their own directory. It is - * written on every run, so that the committed loader of the default directory, and - * that of any other, stay what build_loader() makes rather than drifting from it - * unnoticed. A directory given with `--output-dir` that had none is not included - * by anything yet, so say so. - */ -$loader_path = $output_dir . '/loader.php'; -$loader = build_loader( $output_dir ); -$loader_existed = is_file( $loader_path ); -$loader_contents = $loader_existed ? file_get_contents( $loader_path ) : false; - -if ( $loader !== $loader_contents ) { - if ( false === file_put_contents( $loader_path, $loader ) ) { - fwrite( STDERR, "Could not write $output_option/loader.php\n" ); - exit( 1 ); - } - - printf( - $loader_existed ? "%s: rewritten.\n" : "%s: written. Include it in the configuration for these baselines to take effect.\n", - $output_option . '/loader.php' - ); -} - /* * The command each header gives for regenerating its baseline has to name the * configuration and the directory this run used, where they are not the From 8648fd99c067db53851130aa3631cf027bd9e1d2 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 21:13:36 -0800 Subject: [PATCH 15/30] Build/Test Tools: Name the PHPStan analyses default and strict. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- .../phpstan-pull-request-comments.yml | 97 ++++++++++--------- .../reusable-phpstan-static-analysis-v1.yml | 53 +++++++--- .gitignore | 2 +- composer.json | 4 +- ...l-10.neon.dist => phpstan-strict.neon.dist | 13 +-- phpstan.neon.dist | 2 +- tests/phpstan/README.md | 26 ++--- tests/phpstan/analyse.php | 63 ++++++++---- .../argument.type.neon | 2 +- .../cast.int.neon | 2 +- .../loader.php | 0 .../method.notFound.neon | 2 +- .../missingType.iterableValue.neon | 2 +- .../missingType.return.neon | 2 +- .../offsetAccess.nonOffsetAccessible.neon | 2 +- .../return.type.neon | 2 +- tests/phpstan/generate-baselines.php | 20 ++-- 17 files changed, 177 insertions(+), 117 deletions(-) rename phpstan-level-10.neon.dist => phpstan-strict.neon.dist (87%) rename tests/phpstan/{baselines-level-10 => baselines-strict}/argument.type.neon (98%) rename tests/phpstan/{baselines-level-10 => baselines-strict}/cast.int.neon (96%) rename tests/phpstan/{baselines-level-10 => baselines-strict}/loader.php (100%) rename tests/phpstan/{baselines-level-10 => baselines-strict}/method.notFound.neon (96%) rename tests/phpstan/{baselines-level-10 => baselines-strict}/missingType.iterableValue.neon (98%) rename tests/phpstan/{baselines-level-10 => baselines-strict}/missingType.return.neon (97%) rename tests/phpstan/{baselines-level-10 => baselines-strict}/offsetAccess.nonOffsetAccessible.neon (96%) rename tests/phpstan/{baselines-level-10 => baselines-strict}/return.type.neon (97%) diff --git a/.github/workflows/phpstan-pull-request-comments.yml b/.github/workflows/phpstan-pull-request-comments.yml index d934253193b25..25fd26019c20f 100644 --- a/.github/workflows/phpstan-pull-request-comments.yml +++ b/.github/workflows/phpstan-pull-request-comments.yml @@ -57,16 +57,17 @@ jobs: run-id: ${{ github.event.workflow_run.id }} github-token: ${{ github.token }} - # The results of the analysis holding selected paths to rule level 10. A pull request whose branch does not have - # that analysis yet uploads none, which is fine. Whether they were expected is decided from the results above. - - name: Download the results of the level 10 analysis - id: download-level-10 + # The results of the analysis holding selected paths to a stricter rule level. A pull request whose branch does + # not have that analysis yet uploads none, which is fine. Whether they were expected is decided from the results + # above. + - name: Download the results of the strict analysis + id: download-strict if: ${{ steps.download.outcome == 'success' }} uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 continue-on-error: true with: - name: phpstan-results-level-10 - path: ${{ runner.temp }}/phpstan-results-level-10 + name: phpstan-results-strict + path: ${{ runner.temp }}/phpstan-results-strict run-id: ${{ github.event.workflow_run.id }} github-token: ${{ github.token }} @@ -106,52 +107,57 @@ jobs: const asString = ( value ) => ( typeof value === 'string' ? value : null ); const asSha = ( value ) => ( typeof value === 'string' && /^[0-9a-f]{40}$/.test( value ) ? value : null ); + // A rule level is a number, or `max`. Results from a branch that does not report the level have none. + const asLevel = ( value ) => ( ( Number.isSafeInteger( value ) && value >= 0 ) || value === 'max' ? value : null ); const normalize = ( error ) => ( { file: asString( error.file ), line: Number.isSafeInteger( error.line ) && error.line > 0 ? error.line : null, message: ( asString( error.message ) ?? '' ).slice( 0, 1000 ), identifier: /^[A-Za-z0-9.]+$/.test( error.identifier ) ? error.identifier : null, ignorable: error.ignorable === true, - // The rule level of the analysis that reported the error: 10 for the paths phpstan-level-10.neon.dist - // holds to it, and 5 for everything else, including history recorded before there was a level 10. - level: error.level === 10 ? 10 : 5, + // The analysis that reported the error, and the rule level it analyzed at. Neither is reported per error: + // they are those of the results the error was read from, and are kept in the history from there. + analysis: error.analysis === 'strict' ? 'strict' : 'default', + level: asLevel( error.level ), } ); - // The paths held to rule level 10 are analyzed a second time, and that analysis uploads its results - // separately. The results above list the analyses the run made, and when the level 10 one is among them - // but its results are missing, the comment is left as it is: every error that only analysis reported - // would otherwise be shown as resolved. A run from a branch that does not have that analysis yet lists - // none, and has only these results. - const expectsLevel10 = Array.isArray( results.analyses ) && results.analyses.includes( 'level-10' ); - let level10Errors = []; - if ( expectsLevel10 ) { - let level10Results = null; + // The paths held to a stricter rule level are analyzed a second time, and that analysis uploads its results + // separately. The results above list the analyses the run made, and when the strict one is among them but + // its results are missing, the comment is left as it is: every error that only analysis reported would + // otherwise be shown as resolved. A run from a branch that does not have that analysis yet lists none, and + // has only these results. + const expectsStrict = Array.isArray( results.analyses ) && results.analyses.includes( 'strict' ); + let strictErrors = []; + let strictLevel = null; + if ( expectsStrict ) { + let strictResults = null; try { - level10Results = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-results-level-10/results.json`, 'utf8' ) ); + strictResults = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-results-strict/results.json`, 'utf8' ) ); } catch ( error ) { - core.info( `The results of the level 10 analysis are missing, so the comment is left as it is: ${ error.message }` ); + core.info( `The results of the strict analysis are missing, so the comment is left as it is: ${ error.message }` ); return; } - if ( level10Results?.pull_request !== issue_number || ! Array.isArray( level10Results.errors ) ) { - core.setFailed( 'The results of the level 10 analysis are malformed.' ); + if ( strictResults?.pull_request !== issue_number || ! Array.isArray( strictResults.errors ) ) { + core.setFailed( 'The results of the strict analysis are malformed.' ); return; } - level10Errors = level10Results.errors.map( ( error ) => normalize( { ...error, level: 10 } ) ); + strictLevel = asLevel( strictResults.level ); + strictErrors = strictResults.errors.map( ( error ) => normalize( { ...error, analysis: 'strict', level: strictLevel } ) ); } - // The level 10 analysis includes everything the other one does, so an error it reports at a lower level is + // The strict analysis includes everything the default one does, so an error it reports at a lower level is // reported by both. Such an error is listed once, as found by the analysis of the whole codebase, and the - // level 10 one only adds what is left over. Errors are matched as they are below, apart from their line. + // strict one only adds what is left over. Errors are matched as they are below, apart from their line. const errorKey = ( error ) => JSON.stringify( [ error.file, error.identifier, error.message ] ); - const level5Counts = new Map(); - const level5Errors = results.errors.map( normalize ); - for ( const error of level5Errors ) { - level5Counts.set( errorKey( error ), ( level5Counts.get( errorKey( error ) ) ?? 0 ) + 1 ); + const defaultCounts = new Map(); + const defaultErrors = results.errors.map( ( error ) => normalize( { ...error, analysis: 'default', level: results.level } ) ); + for ( const error of defaultErrors ) { + defaultCounts.set( errorKey( error ), ( defaultCounts.get( errorKey( error ) ) ?? 0 ) + 1 ); } - const level10Only = level10Errors.filter( ( error ) => { - const count = level5Counts.get( errorKey( error ) ) ?? 0; + const strictOnly = strictErrors.filter( ( error ) => { + const count = defaultCounts.get( errorKey( error ) ) ?? 0; if ( count > 0 ) { - level5Counts.set( errorKey( error ), count - 1 ); + defaultCounts.set( errorKey( error ), count - 1 ); return false; } return true; @@ -163,7 +169,7 @@ jobs: // is fixed or added, those after it shift to the history of the one before or after, so their first reports // can be off, and the one shown as resolved or new is the last rather than the one that was. That is rarer // than lines being added or removed above them, which would throw off matching them by line. - const errors = [ ...level5Errors, ...level10Only ]; + const errors = [ ...defaultErrors, ...strictOnly ]; const occurrences = new Map(); for ( const error of [ ...errors ].sort( ( a, b ) => ( a.line ?? 0 ) - ( b.line ?? 0 ) ) ) { const key = errorKey( error ); @@ -262,9 +268,9 @@ jobs: // GitHub shows only the first few annotations of each kind from a step on the page of the workflow run, so // errors left out of a table are pointed to in the log of the step that reported them, which has them all. - // Each analysis runs in a job of its own, and an error found only at level 10 is only in that job's log. - const where = level10Only.length > 0 - ? `the log of the [workflow run](${ run.html_url }), in the “Report the analysis results” step of each of its jobs (level 10 errors are only in the “level 10 paths” job)` + // Each analysis runs in a job of its own, and an error found only by the strict one is only in that job's log. + const where = strictOnly.length > 0 + ? `the log of the [workflow run](${ run.html_url }), in the “Report the analysis results” step of each of its jobs (errors in strict paths are only in the “strict paths” job)` : `the log of the [workflow run](${ run.html_url }), in the “Report the analysis results” step`; const table = ( rows, rowLimit, { withResolution = false } = {} ) => { const shown = rows.slice( 0, rowLimit ); @@ -274,13 +280,14 @@ jobs: : `The ${ rows.length } errors are not listed here, to keep this comment short. They are listed in ${ where }.`; } const more = `…and ${ rows.length - shown.length } more, which are listed in ${ where }.`; - // The rule level is only shown in a table listing an error from the level 10 analysis, so that one listing - // only errors from the analysis of the whole codebase looks as it did before there were two. - const withLevel = shown.some( ( error ) => error.level === 10 ); + // The rule level is only shown in a table listing an error from the strict analysis, so that one listing + // only errors from the analysis of the whole codebase looks as it did before there were two. A level + // that was not reported, as by a branch from before it was, is left blank. + const withLevel = shown.some( ( error ) => error.analysis === 'strict' ); const lines = [ `| Location | Error | Identifier |${ withLevel ? ' Level |' : '' } First reported |${ withResolution ? ' Resolved |' : '' }`, `| --- | --- | --- |${ withLevel ? ' --- |' : '' } --- |${ withResolution ? ' --- |' : '' }`, - ...shown.map( ( error ) => `| ${ location( error ) } | ${ code( error.message ) } | ${ identifier( error ) } |${ withLevel ? ` ${ error.level } |` : '' } ${ commit( error.introduced ) } |${ withResolution ? ` ${ commit( error.fixed ) } |` : '' }` ), + ...shown.map( ( error ) => `| ${ location( error ) } | ${ code( error.message ) } | ${ identifier( error ) } |${ withLevel ? ` ${ error.level ?? '' } |` : '' } ${ commit( error.introduced ) } |${ withResolution ? ` ${ commit( error.fixed ) } |` : '' }` ), ]; if ( shown.length < rows.length ) { lines.push( '', more ); @@ -310,8 +317,10 @@ jobs: `> ${ filesWithLinesOff.size === 1 ? 'A file with errors has' : `${ filesWithLinesOff.size } files with errors have` } changed in ${ code( pr.base.ref ) } since this branch was last updated, so the line numbers reported in ${ filesWithLinesOff.size === 1 ? 'it' : 'them' } may be off and are not linked. Merge the latest ${ code( pr.base.ref ) } into this branch for accurate links.`, ].join( '\n' ) ); } - if ( active.some( ( error ) => error.level === 10 ) ) { - sections.push( `An error at level 10 is in a path that ${ code( 'phpstan-level-10.neon.dist' ) } holds to rule level 10, which the rest of the codebase is not yet held to. See [Stricter analysis of selected paths](${ readmeUrl }#stricter-analysis-of-selected-paths).` ); + if ( active.some( ( error ) => error.analysis === 'strict' ) ) { + const strictError = strictLevel === null ? 'An error found by the strict analysis' : `An error at level ${ strictLevel }`; + const stricterLevel = strictLevel === null ? 'a stricter rule level' : `rule level ${ strictLevel }`; + sections.push( `${ strictError } is in a path that ${ code( 'phpstan-strict.neon.dist' ) } holds to ${ stricterLevel }, which the rest of the codebase is not yet held to. See [Stricter analysis of selected paths](${ readmeUrl }#stricter-analysis-of-selected-paths).` ); } } else { // Resolved by the last commit that resolved anything, so that later commits do not change the comment. @@ -381,8 +390,8 @@ jobs: // The errors tracked are taken in the order they are listed, so that each one listed keeps its history. const tracked = [ ...unignorable, ...ignorable ].slice( 0, trackedLimit ).concat( resolved ).map( ( error ) => { - const { key, file, line, message, identifier, ignorable, level, introduced, seen, fixed } = error; - return { key, file, line: lineMayBeOff( error ) ? null : line, message, identifier, ignorable, level, introduced, seen, fixed }; + const { key, file, line, message, identifier, ignorable, analysis, level, introduced, seen, fixed } = error; + return { key, file, line: lineMayBeOff( error ) ? null : line, message, identifier, ignorable, analysis, level, introduced, seen, fixed }; } ); sections.push( `` ); diff --git a/.github/workflows/reusable-phpstan-static-analysis-v1.yml b/.github/workflows/reusable-phpstan-static-analysis-v1.yml index cdcbe01d1cd43..162dfc54baf9d 100644 --- a/.github/workflows/reusable-phpstan-static-analysis-v1.yml +++ b/.github/workflows/reusable-phpstan-static-analysis-v1.yml @@ -21,8 +21,8 @@ permissions: {} jobs: # Runs PHP static analysis tests. # - # Core is analyzed twice, in parallel: the whole codebase with phpstan.neon.dist, and the paths held to rule level 10 - # with phpstan-level-10.neon.dist. See tests/phpstan/README.md. + # Core is analyzed twice, in parallel: the whole codebase with phpstan.neon.dist, and the paths held to a stricter rule + # level with phpstan-strict.neon.dist. See tests/phpstan/README.md. # # Violations are reported inline with annotations. For pull requests, the results of each analysis are also uploaded # as an artifact, and the PHPStan Pull Request Comments workflow combines them in a comment. @@ -54,16 +54,21 @@ jobs: # The artifact of the analysis of the whole codebase keeps the name it had before there were two, which is # the name the PHPStan Pull Request Comments workflow on trunk requires. That way the comment is kept up to # date for a pull request whose branch does not have the second analysis yet. - - analysis: level-5 + # + # The analyses are named for their role rather than their rule level, which is read from the configuration + # when the results are reported, so that raising either level is an edit of its configuration alone. + - analysis: default label: all paths + config: phpstan.neon.dist baselines: tests/phpstan/baselines - script: phpstan:level-5 + script: phpstan:default artifact: phpstan-results - - analysis: level-10 - label: level 10 paths - baselines: tests/phpstan/baselines-level-10 - script: phpstan:level-10 - artifact: phpstan-results-level-10 + - analysis: strict + label: strict paths + config: phpstan-strict.neon.dist + baselines: tests/phpstan/baselines-strict + script: phpstan:strict + artifact: phpstan-results-strict steps: # For a pull request, the parents of the merge commit are fetched too, to find the files that the base branch @@ -119,9 +124,9 @@ jobs: uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: path: .cache # This is defined in the base.neon file. - key: "phpstan-analysis-cache-${{ matrix.analysis }}-${{ hashFiles('phpstan.neon.dist', 'phpstan-level-10.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}-${{ github.run_id }}" + key: "phpstan-analysis-cache-${{ matrix.analysis }}-${{ hashFiles('phpstan.neon.dist', 'phpstan-strict.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}-${{ github.run_id }}" restore-keys: | - phpstan-analysis-cache-${{ matrix.analysis }}-${{ hashFiles('phpstan.neon.dist', 'phpstan-level-10.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}- + phpstan-analysis-cache-${{ matrix.analysis }}-${{ hashFiles('phpstan.neon.dist', 'phpstan-strict.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}- - name: Run PHP static analysis tests id: phpstan @@ -159,13 +164,32 @@ jobs: uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: ANALYSIS: ${{ matrix.analysis }} + CONFIG: ${{ matrix.config }} with: script: | const fs = require( 'fs' ); + // 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": "?(max|\d+)"?,?$/m ); + if ( match ) { + level = match[ 1 ] === 'max' ? 'max' : Number( match[ 1 ] ); + } + } catch ( error ) { + core.warning( `The rule level of ${ process.env.CONFIG } could not be read: ${ error.message }` ); + } + // Annotations from the stricter analysis say so, since the same code can pass the other one. const analysis = process.env.ANALYSIS; - const titlePrefix = analysis === 'level-10' ? 'PHPStan (level 10)' : 'PHPStan'; + const titlePrefix = analysis === 'strict' ? `PHPStan (strict${ level === null ? '' : `, level ${ level }` })` : 'PHPStan'; const report = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-report.json`, 'utf8' ) ); const workspace = `${ process.env.GITHUB_WORKSPACE }/`; @@ -236,8 +260,9 @@ jobs: fs.writeFileSync( `${ process.env.RUNNER_TEMP }/phpstan-results/results.json`, JSON.stringify( { pull_request: context.payload.pull_request.number, analysis, + level, // Keep this list in step with the `analysis` values of the job's matrix. - ...( analysis === 'level-5' ? { analyses: [ 'level-5', 'level-10' ] } : {} ), + ...( analysis === 'default' ? { analyses: [ 'default', 'strict' ] } : {} ), changed_in_base: changedInBase, errors: errors.map( ( { tip, fixable, ...error } ) => error ), } ) ); @@ -353,7 +378,7 @@ jobs: if: ${{ !cancelled() }} with: path: .cache - key: "phpstan-analysis-cache-${{ matrix.analysis }}-${{ hashFiles('phpstan.neon.dist', 'phpstan-level-10.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}-${{ github.run_id }}" + key: "phpstan-analysis-cache-${{ matrix.analysis }}-${{ hashFiles('phpstan.neon.dist', 'phpstan-strict.neon.dist', 'tests/phpstan/*.neon', 'tests/phpstan/*.php') }}-${{ github.run_id }}" - name: Ensure version-controlled files are not modified or deleted run: git diff --exit-code diff --git a/.gitignore b/.gitignore index 962f5698652b3..24b4282326304 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,7 @@ wp-tests-config.php /tests/phpunit/build /wp-cli.local.yml /phpstan.neon -/phpstan-level-10.neon +/phpstan-strict.neon /*.tsbuildinfo /jsdoc /composer.lock diff --git a/composer.json b/composer.json index b4b6ca8ec79f6..3379966cf8cee 100644 --- a/composer.json +++ b/composer.json @@ -76,8 +76,8 @@ }, "scripts": { "phpstan": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpstan/analyse.php --memory-limit=2G" ], - "phpstan:level-5": "@php ./vendor/bin/phpstan analyse --configuration=phpstan.neon.dist --memory-limit=2G", - "phpstan:level-10": "@php ./vendor/bin/phpstan analyse --configuration=phpstan-level-10.neon.dist --memory-limit=2G", + "phpstan:default": "@php ./vendor/bin/phpstan analyse --configuration=phpstan.neon.dist --memory-limit=2G", + "phpstan:strict": "@php ./vendor/bin/phpstan analyse --configuration=phpstan-strict.neon.dist --memory-limit=2G", "phpstan:baselines": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpstan/generate-baselines.php" ], "phpstan:fix": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpstan/analyse.php --memory-limit=2G --fix" ], "compat": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --standard=phpcompat.xml.dist --report=summary,source", diff --git a/phpstan-level-10.neon.dist b/phpstan-strict.neon.dist similarity index 87% rename from phpstan-level-10.neon.dist rename to phpstan-strict.neon.dist index 6a7f319dae129..ffa58a226d576 100644 --- a/phpstan-level-10.neon.dist +++ b/phpstan-strict.neon.dist @@ -1,15 +1,15 @@ -# PHPStan configuration holding selected parts of WordPress Core to rule level 10. +# PHPStan configuration holding selected parts of WordPress Core to a stricter rule level. # # phpstan.neon.dist analyzes the whole codebase at a lower rule level. This analyzes only the paths listed under -# `paths!` below, at level 10, so that code which already meets the stricter level, mostly code added in recent -# releases, keeps meeting it. `composer phpstan` runs both analyses. +# `paths!` below, at the `level` set below, so that code which already meets that stricter level, mostly code added in +# recent releases, keeps meeting it. `composer phpstan` runs both analyses. # # The rest of core is scanned rather than analyzed, so that what the strict paths use is known. A scanned file is read # with the same WordPress-specific parser node visitors as an analyzed one (see the redefinition of # `currentPhpVersionSimpleParser` in tests/phpstan/base.neon), so a function outside the strict paths has the same # types here, such as the array shapes from hash notation, as in the analysis of the whole codebase. # -# To override this configuration, create a phpstan-level-10.neon which includes this file, in the same way as +# To override this configuration, create a phpstan-strict.neon which includes this file, in the same way as # phpstan.neon overrides phpstan.neon.dist. # # https://phpstan.org/config-reference @@ -24,16 +24,17 @@ includes: # Preexisting errors at this level in the strict paths, beyond those baselined by phpstan.neon.dist. They are # organized and regenerated the same way, by `composer phpstan:baselines`, and included the same way, through the # loader in their directory. - - tests/phpstan/baselines-level-10/loader.php + - tests/phpstan/baselines-strict/loader.php parameters: + # The level is set explicitly rather than as `max`, so that a PHPStan update that adds a level does not raise it. # https://phpstan.org/user-guide/rule-levels level: 10 # The two analyses share the cache of what PHPStan reads from each file, since both read every file the same way, # but each needs its own result cache. Its metadata includes the rule level and the paths analyzed, so a shared one # would be discarded by every run of the other analysis. - resultCachePath: %tmpDir%/resultCache-level-10.php + resultCachePath: %tmpDir%/resultCache-strict.php # The paths held to this rule level, replacing those analyzed by phpstan.neon.dist. A directory covers every file # below it. diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 421aef0b7757c..796646255ada6 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,6 +1,6 @@ # PHPStan configuration for WordPress Core. # -# This analyzes the whole codebase. phpstan-level-10.neon.dist includes it, and holds selected +# This analyzes the whole codebase. phpstan-strict.neon.dist includes it, and holds selected # paths to a stricter rule level. `composer phpstan` runs both. # # To override this configuration, create a phpstan.neon which includes this file and adjusts diff --git a/tests/phpstan/README.md b/tests/phpstan/README.md index 5ba4d8a3b5ec3..6efa32fb159f7 100644 --- a/tests/phpstan/README.md +++ b/tests/phpstan/README.md @@ -16,7 +16,7 @@ npm run typecheck:php which will run PHPStan in the Docker container. -This runs two analyses, one after the other: the whole codebase with [`phpstan.neon.dist`](../../phpstan.neon.dist), and then the paths held to a stricter rule level with [`phpstan-level-10.neon.dist`](../../phpstan-level-10.neon.dist), as described in [Stricter analysis of selected paths](#stricter-analysis-of-selected-paths). The command fails when either of them reports an error. +This runs two analyses, one after the other: the whole codebase with [`phpstan.neon.dist`](../../phpstan.neon.dist), and then the paths held to a stricter rule level with [`phpstan-strict.neon.dist`](../../phpstan-strict.neon.dist), as described in [Stricter analysis of selected paths](#stricter-analysis-of-selected-paths). The command fails when either of them reports an error. Additional flags supported by PHPStan can be passed by passing `--` followed by the flags themselves. For example, @@ -43,7 +43,7 @@ composer run phpstan -- -vvv --debug Note the `--` in each of those. Composer needs it in order to pass the flags on to PHPStan rather than reading them as its own, and without it they are discarded silently. The npm script supplies it, which is why only one is needed there. -The flags are passed to both analyses, except that paths, `--configuration`, `--level`, `--error-format`, `--generate-baseline`, and `--fix-ignored` run only the first, since each only makes sense for one. To run only one of them, as CI does, use `composer phpstan:level-5` or `composer phpstan:level-10`. Those always use the `.dist` configurations, ignoring a local override. +The flags are passed to both analyses, except that paths, `--configuration`, `--level`, `--error-format`, `--generate-baseline`, and `--fix-ignored` run only the first, since each only makes sense for one. To run only one of them, as CI does, use `composer phpstan:default` or `composer phpstan:strict`. Those always use the `.dist` configurations, ignoring a local override. For available flags, see https://phpstan.org/user-guide/command-line-usage. @@ -52,7 +52,7 @@ For available flags, see https://phpstan.org/user-guide/command-line-usage. Both analyses also run on every pull request that changes PHP files or the PHPStan configuration, as two jobs. The errors they report are shown in two places: - As annotations on the changed files. Most errors are annotated as warnings, which do not fail the check. -- In a comment on the pull request, which lists every error in a table along with the commit it was first reported for. The comment is updated as new commits are pushed, moving each error that a commit resolves into a collapsed list of resolved errors, which also names that commit. Once all of the errors are resolved, the comment is marked as resolved and collapsed. The comment combines both analyses: an error reported by both is listed once, and when an error is only reported at level 10, the table gains a Level column saying so. +- In a comment on the pull request, which lists every error in a table along with the commit it was first reported for. The comment is updated as new commits are pushed, moving each error that a commit resolves into a collapsed list of resolved errors, which also names that commit. Once all of the errors are resolved, the comment is marked as resolved and collapsed. The comment combines both analyses: an error reported by both is listed once, and when an error is only reported by the analysis of the strict paths, the table gains a Level column giving the rule level of each error. Some errors cannot be ignored, and so cannot be reported as warnings either. These fail the check. The most common is an [out-of-date baseline](#removing-stale-entries-with---fix), which is reported when an error recorded in a baseline was fixed without the baseline being updated. Such an error is reported against a file rather than a line in it, so its annotation does not appear alongside the changes, and it would easily go unnoticed if the check passed. @@ -110,22 +110,22 @@ parameters: ### Stricter analysis of selected paths -`phpstan.neon.dist` holds the whole codebase to a low rule level, since most of it does not yet meet a higher one. Some of it already does, mostly code added in recent releases, such as the AI client and the Abilities API. [`phpstan-level-10.neon.dist`](../../phpstan-level-10.neon.dist) holds those paths to rule level 10, so that they keep meeting it. +`phpstan.neon.dist` holds the whole codebase to a low rule level, since most of it does not yet meet a higher one. Some of it already does, mostly code added in recent releases, such as the AI client and the Abilities API. [`phpstan-strict.neon.dist`](../../phpstan-strict.neon.dist) holds those paths to a stricter rule level, currently 10, so that they keep meeting it. The level is set as a number rather than `max`, so that it is only raised deliberately, not by a PHPStan update adding a level. It includes `phpstan.neon.dist`, so everything that enforces still applies, and replaces the paths analyzed with the ones it lists under `paths!`. The rest of core is scanned instead, so that what those paths use is known. A scanned file gets the same [WordPress-specific extensions](#wordpress-specific-extensions) as an analyzed one, because `base.neon` has every parse run them, so the types of the code outside the strict paths are the same as in the analysis of the whole codebase. -Errors are baselined in two layers. An error that the analysis of the whole codebase reports is baselined in [`baselines/`](baselines), as usual, and stays baselined there for the level 10 analysis. What level 10 adds in the strict paths is baselined in [`baselines-level-10/`](baselines-level-10), in the same way, and included through its own [`loader.php`](baselines-level-10/loader.php). `composer phpstan:baselines` and `composer phpstan:fix` maintain both. +Errors are baselined in two layers. An error that the analysis of the whole codebase reports is baselined in [`baselines/`](baselines), as usual, and stays baselined there for the strict analysis. What the stricter level adds in the strict paths is baselined in [`baselines-strict/`](baselines-strict), in the same way, and included through its own [`loader.php`](baselines-strict/loader.php). `composer phpstan:baselines` and `composer phpstan:fix` maintain both. -To hold another path to level 10: +To hold another path to the stricter level: 1. Make sure no entry in [`baselines/`](baselines) is for a file in the path. Both analyses enforce those entries, but each may report a different number of the errors one ignores, and then no count satisfies both. Fix those errors first. -2. Add the path to `paths!` in `phpstan-level-10.neon.dist`. -3. Run `composer phpstan:level-10`, and fix the errors it reports. +2. Add the path to `paths!` in `phpstan-strict.neon.dist`. +3. Run `composer phpstan:strict`, and fix the errors it reports. 4. Baseline any that cannot be fixed yet with `composer phpstan:baselines`. -In the strict paths, **do not add an `@phpstan-ignore` comment for an error that only levels 6 to 10 report**. The analysis of the whole codebase does not report that error, so it reports the comment as ignoring nothing, and `composer phpstan:fix` would remove it. Fix the error, or baseline it instead. +In the strict paths, **do not add an `@phpstan-ignore` comment for an error that only the stricter level reports**. The analysis of the whole codebase does not report that error, so it reports the comment as ignoring nothing, and `composer phpstan:fix` would remove it. Fix the error, or baseline it instead. -A local `phpstan-level-10.neon` overrides `phpstan-level-10.neon.dist`, the same way `phpstan.neon` overrides `phpstan.neon.dist`. When a local `phpstan.neon` already analyzes everything at level 10, `composer phpstan` skips the second analysis, since it could only repeat part of the first. +A local `phpstan-strict.neon` overrides `phpstan-strict.neon.dist`, the same way `phpstan.neon` overrides `phpstan.neon.dist`. When a local `phpstan.neon` already analyzes everything at the strict level or above, `composer phpstan` skips the second analysis, since it could only repeat part of the first. For more information about configuring PHPStan, see the [PHPStan documentation's Config reference](https://phpstan.org/config-reference). @@ -259,13 +259,13 @@ composer phpstan:fix This runs three steps: -1. PHPStan with its `--fix` option, once with `phpstan.neon.dist` and once with `phpstan-level-10.neon.dist`. It lowers the count of the entry, or removes the entry, leaving the rest of the baseline as it was. It is usually much faster than regenerating, since it reuses the result cache of the run that reported the errors. Unlike regenerating, it also removes an `@phpstan-ignore` comment that no longer matches. PHPStan says `No fixable errors found` for a configuration with nothing to fix, which does not stop the other steps. +1. PHPStan with its `--fix` option, once with `phpstan.neon.dist` and once with `phpstan-strict.neon.dist`. It lowers the count of the entry, or removes the entry, leaving the rest of the baseline as it was. It is usually much faster than regenerating, since it reuses the result cache of the run that reported the errors. Unlike regenerating, it also removes an `@phpstan-ignore` comment that no longer matches. PHPStan says `No fixable errors found` for a configuration with nothing to fix, which does not stop the other steps. 2. `composer phpstan:baselines -- --prune`, which deletes any baseline left with no entries. Removing the last entry of a baseline leaves the file behind, as `ignoreErrors: []`. Pruning analyzes nothing, so it can also be run on its own. 3. Both analyses once more, which reuse the result cache and so are quick. PHPStan's `--fix` reports only what it fixed, and succeeds even when other errors remain, so this is what shows the errors that are left. Keep in mind: -- **It always analyzes with the two `.dist` configurations**, whatever a local `phpstan.neon` or `phpstan-level-10.neon` says. A configuration at another rule level can report a baselined error with a different message, in which case `--fix` would remove an entry that the default configuration still needs. +- **It always analyzes with the two `.dist` configurations**, whatever a local `phpstan.neon` or `phpstan-strict.neon` says. A configuration at another rule level can report a baselined error with a different message, in which case `--fix` would remove an entry that the default configuration still needs. - **It fixes every fixable error the run reports**, not only stale ignores. A few other errors can also be fixed automatically, such as a [useless cast](https://phpstan.org/error-identifiers/cast.useless), so check the diff before committing it. - PHPStan's `--fix-ignored`, run as `composer phpstan -- --fix-ignored`, goes further and also fixes the fixable errors which a baseline currently ignores. That is a way to work through a baseline, but expect larger diffs, and follow it with `composer phpstan:baselines -- --prune`. @@ -316,7 +316,7 @@ Note the `--` in each of those. Composer needs it in order to pass the flags on A run also deletes any baseline whose identifier no longer reports anything. Since the baselines are included through [`baselines/loader.php`](baselines/loader.php), adding a newly split out baseline, and retiring one that has reached zero, need no edit of the configuration. -Each run regenerates both sets of baselines: those of `phpstan.neon.dist` in [`baselines/`](baselines), and then those of `phpstan-level-10.neon.dist` in [`baselines-level-10/`](baselines-level-10). The order matters, since the level 10 configuration includes the other one along with its baselines, so its own are only what is left over. The options apply to both, except `--combined`, which only prints the baseline of `phpstan.neon.dist`. To regenerate one set, name its configuration with `--config`, such as `--config=phpstan-level-10.neon.dist`. +Each run regenerates both sets of baselines: those of `phpstan.neon.dist` in [`baselines/`](baselines), and then those of `phpstan-strict.neon.dist` in [`baselines-strict/`](baselines-strict). The order matters, since the strict configuration includes the other one along with its baselines, so its own are only what is left over. The options apply to both, except `--combined`, which only prints the baseline of `phpstan.neon.dist`. To regenerate one set, name its configuration with `--config`, such as `--config=phpstan-strict.neon.dist`. PHPStan's own `--generate-baseline` is deliberately not used directly. It captures every error a run reports, with no way to restrict it to one identifier, so it cannot refresh a single baseline without sweeping every other kind of error into it. diff --git a/tests/phpstan/analyse.php b/tests/phpstan/analyse.php index eaf5cc2cdfc11..608dab268ff4b 100644 --- a/tests/phpstan/analyse.php +++ b/tests/phpstan/analyse.php @@ -3,17 +3,17 @@ * Runs the PHPStan analyses of WordPress core. * * Core is analyzed twice: the whole codebase with phpstan.neon.dist, and then the - * paths held to a stricter rule level with phpstan-level-10.neon.dist. A Composer + * paths held to a stricter rule level with phpstan-strict.neon.dist. A Composer * script listing the two would stop at the first, since PHPStan exits with a * failure status whenever it reports an error, so this runs each in turn whatever * the other reports, and exits with the highest status of them. * * Each analysis honors a local override of its configuration, the same way * PHPStan does: phpstan.neon in place of phpstan.neon.dist, which PHPStan finds by - * itself, and phpstan-level-10.neon in place of phpstan-level-10.neon.dist, which + * itself, and phpstan-strict.neon in place of phpstan-strict.neon.dist, which * this script chooses. When a local phpstan.neon already analyzes the whole - * codebase at level 10, the second analysis could only repeat some of what the - * first reported, so it is skipped. + * codebase at the strict rule level or above, the second analysis could only + * repeat some of what the first reported, so it is skipped. * * With `--fix`, the stale entries of both sets of baselines are fixed instead, * along with anything else PHPStan can fix. That always uses the two .dist @@ -52,7 +52,7 @@ /** * The configuration holding selected paths to a stricter rule level. */ -const STRICT_CONFIG = 'phpstan-level-10.neon.dist'; +const STRICT_CONFIG = 'phpstan-strict.neon.dist'; $repo_root = dirname( __DIR__, 2 ); $phpstan = $repo_root . '/vendor/bin/phpstan'; @@ -73,10 +73,10 @@ /* * Some arguments only make sense for a single analysis. Paths would replace the - * strict paths of the second one, holding whatever they name to level 10; a level - * would analyze the strict paths at another; a report format meant to be read by - * a program would print two reports in a row; and a baseline would be written by - * each in turn. With any of them, only the first analysis runs, as it did before + * strict paths of the second one, holding whatever they name to the stricter + * level; a level would analyze the strict paths at another; a report format meant + * to be read by a program would print two reports in a row; and a baseline would + * be written by each in turn. With any of them, only the first analysis runs, as it did before * there were two. */ $single_reason = get_single_analysis_reason( $args ); @@ -113,14 +113,19 @@ } $local_config = $repo_root . '/phpstan.neon'; -$strict_config = is_file( $repo_root . '/phpstan-level-10.neon' ) ? 'phpstan-level-10.neon' : STRICT_CONFIG; +$strict_config = is_file( $repo_root . '/phpstan-strict.neon' ) ? 'phpstan-strict.neon' : STRICT_CONFIG; // PHPStan reads phpstan.neon in place of phpstan.neon.dist by itself, so the first analysis names neither. $exit_code = run( 'Analyzing with ' . ( is_file( $local_config ) ? 'phpstan.neon' : PROJECT_CONFIG ), $phpstan, $args ); -if ( is_file( $local_config ) && is_strictest_level( $phpstan, $local_config ) ) { - fwrite( STDERR, "\nSkipping $strict_config: phpstan.neon already analyzes every path at level 10.\n" ); - exit( $exit_code ); +if ( is_file( $local_config ) ) { + $local_level = get_level( $phpstan, $local_config ); + $strict_level = get_level( $phpstan, $repo_root . '/' . $strict_config ); + + if ( null !== $local_level && null !== $strict_level && is_level_at_least( $local_level, $strict_level ) ) { + fwrite( STDERR, "\nSkipping $strict_config: phpstan.neon already analyzes every path at level $local_level, and the strict paths are held to $strict_level.\n" ); + exit( $exit_code ); + } } exit( max( $exit_code, run( "Analyzing the strict paths with $strict_config", $phpstan, array_merge( array( "--configuration=$strict_config" ), $args ) ) ) ); @@ -158,7 +163,7 @@ function run( string $heading, string $script, array $args, bool $is_analysis = } /** - * Determines whether a configuration analyzes at the strictest rule level. + * Gets the rule level a configuration analyzes at. * * 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 @@ -166,21 +171,41 @@ function run( string $heading, string $script, array $args, bool $is_analysis = * * @param string $phpstan Path to the PHPStan executable. * @param string $config Absolute path to the configuration file. - * @return bool Whether the configuration's rule level is 10 or `max`. + * @return string|null The rule level, as digits or `max`, or null if it could not be read. */ -function is_strictest_level( string $phpstan, string $config ): bool { +function get_level( string $phpstan, string $config ): ?string { $output = array(); $exit_code = 0; exec( sprintf( '%s %s dump-parameters --configuration=%s --json 2>/dev/null', escapeshellarg( PHP_BINARY ), escapeshellarg( $phpstan ), escapeshellarg( $config ) ), $output, $exit_code ); foreach ( $output as $line ) { if ( 1 === preg_match( '/^\s*"level": ("max"|"?\d+"?),?$/', $line, $matches ) ) { - $level = trim( $matches[1], '"' ); - return 'max' === $level || (int) $level >= 10; + return trim( $matches[1], '"' ); } } - return false; + return null; +} + +/** + * Determines whether a rule level is at least as strict as another. + * + * `max` is the highest level of whichever PHPStan version is installed, so it is + * at least any other. A numbered level is not taken to be at least `max`, since + * that would only hold until PHPStan adds a level above it. + * + * @param string $level Rule level, as digits or `max`. + * @param string $minimum Rule level to compare it with, as digits or `max`. + * @return bool Whether the level is at least the minimum. + */ +function is_level_at_least( string $level, string $minimum ): bool { + if ( 'max' === $level ) { + return true; + } + if ( 'max' === $minimum ) { + return false; + } + return (int) $level >= (int) $minimum; } /** diff --git a/tests/phpstan/baselines-level-10/argument.type.neon b/tests/phpstan/baselines-strict/argument.type.neon similarity index 98% rename from tests/phpstan/baselines-level-10/argument.type.neon rename to tests/phpstan/baselines-strict/argument.type.neon index ab4a4096ee3d9..a0c14db69b575 100644 --- a/tests/phpstan/baselines-level-10/argument.type.neon +++ b/tests/phpstan/baselines-strict/argument.type.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with # -# composer phpstan:baselines -- --identifier=argument.type --config=phpstan-level-10.neon.dist +# composer phpstan:baselines -- --identifier=argument.type --config=phpstan-strict.neon.dist # # which reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines-level-10/cast.int.neon b/tests/phpstan/baselines-strict/cast.int.neon similarity index 96% rename from tests/phpstan/baselines-level-10/cast.int.neon rename to tests/phpstan/baselines-strict/cast.int.neon index 6c499dbf87337..32c16d73885b2 100644 --- a/tests/phpstan/baselines-level-10/cast.int.neon +++ b/tests/phpstan/baselines-strict/cast.int.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with # -# composer phpstan:baselines -- --identifier=cast.int --config=phpstan-level-10.neon.dist +# composer phpstan:baselines -- --identifier=cast.int --config=phpstan-strict.neon.dist # # which reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines-level-10/loader.php b/tests/phpstan/baselines-strict/loader.php similarity index 100% rename from tests/phpstan/baselines-level-10/loader.php rename to tests/phpstan/baselines-strict/loader.php diff --git a/tests/phpstan/baselines-level-10/method.notFound.neon b/tests/phpstan/baselines-strict/method.notFound.neon similarity index 96% rename from tests/phpstan/baselines-level-10/method.notFound.neon rename to tests/phpstan/baselines-strict/method.notFound.neon index d9d38de55f0f5..7127595167b91 100644 --- a/tests/phpstan/baselines-level-10/method.notFound.neon +++ b/tests/phpstan/baselines-strict/method.notFound.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with # -# composer phpstan:baselines -- --identifier=method.notFound --config=phpstan-level-10.neon.dist +# composer phpstan:baselines -- --identifier=method.notFound --config=phpstan-strict.neon.dist # # which reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines-level-10/missingType.iterableValue.neon b/tests/phpstan/baselines-strict/missingType.iterableValue.neon similarity index 98% rename from tests/phpstan/baselines-level-10/missingType.iterableValue.neon rename to tests/phpstan/baselines-strict/missingType.iterableValue.neon index ade711c82080e..a174fca5a6d4f 100644 --- a/tests/phpstan/baselines-level-10/missingType.iterableValue.neon +++ b/tests/phpstan/baselines-strict/missingType.iterableValue.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with # -# composer phpstan:baselines -- --identifier=missingType.iterableValue --config=phpstan-level-10.neon.dist +# composer phpstan:baselines -- --identifier=missingType.iterableValue --config=phpstan-strict.neon.dist # # which reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines-level-10/missingType.return.neon b/tests/phpstan/baselines-strict/missingType.return.neon similarity index 97% rename from tests/phpstan/baselines-level-10/missingType.return.neon rename to tests/phpstan/baselines-strict/missingType.return.neon index 564a294d0416d..8cfa903d2f2aa 100644 --- a/tests/phpstan/baselines-level-10/missingType.return.neon +++ b/tests/phpstan/baselines-strict/missingType.return.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with # -# composer phpstan:baselines -- --identifier=missingType.return --config=phpstan-level-10.neon.dist +# composer phpstan:baselines -- --identifier=missingType.return --config=phpstan-strict.neon.dist # # which reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon b/tests/phpstan/baselines-strict/offsetAccess.nonOffsetAccessible.neon similarity index 96% rename from tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon rename to tests/phpstan/baselines-strict/offsetAccess.nonOffsetAccessible.neon index e8535ce4063e3..cbcda7e7b0d37 100644 --- a/tests/phpstan/baselines-level-10/offsetAccess.nonOffsetAccessible.neon +++ b/tests/phpstan/baselines-strict/offsetAccess.nonOffsetAccessible.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with # -# composer phpstan:baselines -- --identifier=offsetAccess.nonOffsetAccessible --config=phpstan-level-10.neon.dist +# composer phpstan:baselines -- --identifier=offsetAccess.nonOffsetAccessible --config=phpstan-strict.neon.dist # # which reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines-level-10/return.type.neon b/tests/phpstan/baselines-strict/return.type.neon similarity index 97% rename from tests/phpstan/baselines-level-10/return.type.neon rename to tests/phpstan/baselines-strict/return.type.neon index 4501ea499badd..08c4a20b826f4 100644 --- a/tests/phpstan/baselines-level-10/return.type.neon +++ b/tests/phpstan/baselines-strict/return.type.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with # -# composer phpstan:baselines -- --identifier=return.type --config=phpstan-level-10.neon.dist +# composer phpstan:baselines -- --identifier=return.type --config=phpstan-strict.neon.dist # # which reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/generate-baselines.php b/tests/phpstan/generate-baselines.php index dfad8bb14ef63..1383da617750f 100644 --- a/tests/phpstan/generate-baselines.php +++ b/tests/phpstan/generate-baselines.php @@ -19,7 +19,7 @@ * * Unless a configuration is named, this is done for each of DEFAULT_CONFIGS in * turn: phpstan.neon.dist, which analyzes the whole codebase, and then - * phpstan-level-10.neon.dist, which holds selected paths to a stricter rule level + * phpstan-strict.neon.dist, which holds selected paths to a stricter rule level * and includes the former along with its baselines. * * With `--prune`, nothing is analyzed: the baselines that no longer list any @@ -66,15 +66,15 @@ * The configurations processed when neither `--config` nor `--output-dir` is given, * each with the directory its baselines are written to. * - * They are processed in this order, which matters: phpstan-level-10.neon.dist + * They are processed in this order, which matters: phpstan-strict.neon.dist * includes phpstan.neon.dist along with its baselines, so its own are only what is * left over once those are up to date. * * Relative to the repository root. */ const DEFAULT_CONFIGS = array( - DEFAULT_CONFIG => DEFAULT_OUTPUT_DIR, - 'phpstan-level-10.neon.dist' => 'tests/phpstan/baselines-level-10', + DEFAULT_CONFIG => DEFAULT_OUTPUT_DIR, + 'phpstan-strict.neon.dist' => 'tests/phpstan/baselines-strict', ); if ( 'cli' !== PHP_SAPI ) { @@ -193,10 +193,10 @@ /* * A default configuration named without an output directory writes to its own, - * so that naming phpstan-level-10.neon.dist alone cannot write its baselines over + * so that naming phpstan-strict.neon.dist alone cannot write its baselines over * those of phpstan.neon.dist. So does a local override of one, such as - * phpstan-level-10.neon, named as the `.dist` file is but without the suffix. - * Written to the default directory instead, the level 10 analysis of only the + * phpstan-strict.neon, named as the `.dist` file is but without the suffix. + * Written to the default directory instead, the stricter analysis of only the * strict paths, with the baselines there suppressed, would retire every baseline of * the whole codebase it does not report again. */ @@ -550,8 +550,8 @@ function get_usage(): string { edit of it. Without --config or --output-dir, this is done for phpstan.neon.dist into - tests/phpstan/baselines, and then for phpstan-level-10.neon.dist into - tests/phpstan/baselines-level-10. The other options apply to both. + tests/phpstan/baselines, and then for phpstan-strict.neon.dist into + tests/phpstan/baselines-strict. The other options apply to both. Usage: composer phpstan:baselines [-- ] @@ -573,7 +573,7 @@ function get_usage(): string { they leave are written. Default: the directory of the configuration named above, or of the one it overrides locally, such as - phpstan-level-10.neon, or else tests/phpstan/baselines + phpstan-strict.neon, or else tests/phpstan/baselines --combined Print one combined baseline to stdout instead of writing per-identifier files. Nothing is written to disk. Only phpstan.neon.dist is analyzed, unless --config names From 618a81bd6b5f54deb40b4215c18549315b7bf6c3 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 21:32:15 -0800 Subject: [PATCH 16/30] Build/Test Tools: Pass the encoding of PHPStan results as an option. `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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- .github/workflows/phpstan-pull-request-comments.yml | 4 ++-- .github/workflows/reusable-phpstan-static-analysis-v1.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpstan-pull-request-comments.yml b/.github/workflows/phpstan-pull-request-comments.yml index 25fd26019c20f..d768ec9adc4b5 100644 --- a/.github/workflows/phpstan-pull-request-comments.yml +++ b/.github/workflows/phpstan-pull-request-comments.yml @@ -88,7 +88,7 @@ jobs: // anything at all. They are therefore checked for shape, and only accepted for the pull request whose // current head is the commit that the run analyzed. That also discards the results of a run that was // overtaken by a newer push. - const results = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-results/results.json`, 'utf8' ) ); + const results = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-results/results.json`, { encoding: 'utf8' } ) ); const issue_number = results.pull_request; if ( ! Number.isSafeInteger( issue_number ) || issue_number <= 0 || ! Array.isArray( results.errors ) ) { core.setFailed( 'The analysis results are malformed.' ); @@ -132,7 +132,7 @@ jobs: if ( expectsStrict ) { let strictResults = null; try { - strictResults = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-results-strict/results.json`, 'utf8' ) ); + strictResults = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-results-strict/results.json`, { encoding: 'utf8' } ) ); } catch ( error ) { core.info( `The results of the strict analysis are missing, so the comment is left as it is: ${ error.message }` ); return; diff --git a/.github/workflows/reusable-phpstan-static-analysis-v1.yml b/.github/workflows/reusable-phpstan-static-analysis-v1.yml index 162dfc54baf9d..608b378da89fc 100644 --- a/.github/workflows/reusable-phpstan-static-analysis-v1.yml +++ b/.github/workflows/reusable-phpstan-static-analysis-v1.yml @@ -191,7 +191,7 @@ jobs: const analysis = process.env.ANALYSIS; const titlePrefix = analysis === 'strict' ? `PHPStan (strict${ level === null ? '' : `, level ${ level }` })` : 'PHPStan'; - const report = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-report.json`, 'utf8' ) ); + const report = JSON.parse( fs.readFileSync( `${ process.env.RUNNER_TEMP }/phpstan-report.json`, { encoding: 'utf8' } ) ); const workspace = `${ process.env.GITHUB_WORKSPACE }/`; const errors = []; From 702a2fbf725b2e83b6c634ae4d8e86b9d2c47ab8 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 22:18:42 -0800 Subject: [PATCH 17/30] Build/Test Tools: Split the sentence regenerating a PHPStan baseline. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/baselines-strict/argument.type.neon | 4 ++-- tests/phpstan/baselines-strict/cast.int.neon | 4 ++-- tests/phpstan/baselines-strict/method.notFound.neon | 4 ++-- tests/phpstan/baselines-strict/missingType.iterableValue.neon | 4 ++-- tests/phpstan/baselines-strict/missingType.return.neon | 4 ++-- .../baselines-strict/offsetAccess.nonOffsetAccessible.neon | 4 ++-- tests/phpstan/baselines-strict/return.type.neon | 4 ++-- tests/phpstan/baselines/argument.type.neon | 4 ++-- tests/phpstan/baselines/argument.unresolvableType.neon | 4 ++-- tests/phpstan/baselines/assign.propertyType.neon | 4 ++-- tests/phpstan/baselines/binaryOp.invalid.neon | 4 ++-- tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon | 4 ++-- tests/phpstan/baselines/booleanNot.alwaysTrue.neon | 4 ++-- tests/phpstan/baselines/class.notFound.neon | 4 ++-- tests/phpstan/baselines/deadCode.unreachable.neon | 4 ++-- tests/phpstan/baselines/empty.property.neon | 4 ++-- tests/phpstan/baselines/empty.variable.neon | 4 ++-- tests/phpstan/baselines/function.alreadyNarrowedType.neon | 4 ++-- tests/phpstan/baselines/function.resultUnused.neon | 4 ++-- tests/phpstan/baselines/identical.alwaysFalse.neon | 4 ++-- tests/phpstan/baselines/if.alwaysFalse.neon | 4 ++-- tests/phpstan/baselines/if.alwaysTrue.neon | 4 ++-- tests/phpstan/baselines/isset.property.neon | 4 ++-- tests/phpstan/baselines/method.childParameterType.neon | 4 ++-- tests/phpstan/baselines/method.unused.neon | 4 ++-- tests/phpstan/baselines/notIdentical.alwaysTrue.neon | 4 ++-- tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon | 4 ++-- tests/phpstan/baselines/offsetAccess.notFound.neon | 4 ++-- tests/phpstan/baselines/offsetAssign.valueType.neon | 4 ++-- tests/phpstan/baselines/parameterByRef.type.neon | 4 ++-- tests/phpstan/baselines/parameterByRef.unusedType.neon | 4 ++-- tests/phpstan/baselines/property.defaultValue.neon | 4 ++-- tests/phpstan/baselines/property.nonObject.neon | 4 ++-- tests/phpstan/baselines/property.notFound.neon | 4 ++-- tests/phpstan/baselines/property.private.neon | 4 ++-- tests/phpstan/baselines/return.type.neon | 4 ++-- tests/phpstan/baselines/varTag.noVariable.neon | 4 ++-- tests/phpstan/baselines/variable.undefined.neon | 4 ++-- tests/phpstan/generate-baselines.php | 4 ++-- 39 files changed, 78 insertions(+), 78 deletions(-) diff --git a/tests/phpstan/baselines-strict/argument.type.neon b/tests/phpstan/baselines-strict/argument.type.neon index a0c14db69b575..dd83b950de430 100644 --- a/tests/phpstan/baselines-strict/argument.type.neon +++ b/tests/phpstan/baselines-strict/argument.type.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=argument.type --config=phpstan-strict.neon.dist # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines-strict/cast.int.neon b/tests/phpstan/baselines-strict/cast.int.neon index 32c16d73885b2..afa3e42a72b97 100644 --- a/tests/phpstan/baselines-strict/cast.int.neon +++ b/tests/phpstan/baselines-strict/cast.int.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=cast.int --config=phpstan-strict.neon.dist # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines-strict/method.notFound.neon b/tests/phpstan/baselines-strict/method.notFound.neon index 7127595167b91..2af618ef0326c 100644 --- a/tests/phpstan/baselines-strict/method.notFound.neon +++ b/tests/phpstan/baselines-strict/method.notFound.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=method.notFound --config=phpstan-strict.neon.dist # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines-strict/missingType.iterableValue.neon b/tests/phpstan/baselines-strict/missingType.iterableValue.neon index a174fca5a6d4f..862bff081da41 100644 --- a/tests/phpstan/baselines-strict/missingType.iterableValue.neon +++ b/tests/phpstan/baselines-strict/missingType.iterableValue.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=missingType.iterableValue --config=phpstan-strict.neon.dist # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines-strict/missingType.return.neon b/tests/phpstan/baselines-strict/missingType.return.neon index 8cfa903d2f2aa..437bea89ac68d 100644 --- a/tests/phpstan/baselines-strict/missingType.return.neon +++ b/tests/phpstan/baselines-strict/missingType.return.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=missingType.return --config=phpstan-strict.neon.dist # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines-strict/offsetAccess.nonOffsetAccessible.neon b/tests/phpstan/baselines-strict/offsetAccess.nonOffsetAccessible.neon index cbcda7e7b0d37..ffac0d73e3744 100644 --- a/tests/phpstan/baselines-strict/offsetAccess.nonOffsetAccessible.neon +++ b/tests/phpstan/baselines-strict/offsetAccess.nonOffsetAccessible.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=offsetAccess.nonOffsetAccessible --config=phpstan-strict.neon.dist # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines-strict/return.type.neon b/tests/phpstan/baselines-strict/return.type.neon index 08c4a20b826f4..891a38598dedd 100644 --- a/tests/phpstan/baselines-strict/return.type.neon +++ b/tests/phpstan/baselines-strict/return.type.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=return.type --config=phpstan-strict.neon.dist # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/argument.type.neon b/tests/phpstan/baselines/argument.type.neon index dd184d5a12924..6427acb3e2a01 100644 --- a/tests/phpstan/baselines/argument.type.neon +++ b/tests/phpstan/baselines/argument.type.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=argument.type # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/argument.unresolvableType.neon b/tests/phpstan/baselines/argument.unresolvableType.neon index 8bee3995f6ac5..f837a9dcb3560 100644 --- a/tests/phpstan/baselines/argument.unresolvableType.neon +++ b/tests/phpstan/baselines/argument.unresolvableType.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=argument.unresolvableType # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/assign.propertyType.neon b/tests/phpstan/baselines/assign.propertyType.neon index 4afc274001850..a0aebabe9f5cd 100644 --- a/tests/phpstan/baselines/assign.propertyType.neon +++ b/tests/phpstan/baselines/assign.propertyType.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=assign.propertyType # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/binaryOp.invalid.neon b/tests/phpstan/baselines/binaryOp.invalid.neon index 57b8bf343662e..a294ec62ed775 100644 --- a/tests/phpstan/baselines/binaryOp.invalid.neon +++ b/tests/phpstan/baselines/binaryOp.invalid.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=binaryOp.invalid # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon b/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon index 23523d7b66739..6cf262ecf88d6 100644 --- a/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon +++ b/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=booleanAnd.leftAlwaysTrue # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/booleanNot.alwaysTrue.neon b/tests/phpstan/baselines/booleanNot.alwaysTrue.neon index 066ee954ba210..1fe2aefba14d0 100644 --- a/tests/phpstan/baselines/booleanNot.alwaysTrue.neon +++ b/tests/phpstan/baselines/booleanNot.alwaysTrue.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=booleanNot.alwaysTrue # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/class.notFound.neon b/tests/phpstan/baselines/class.notFound.neon index 423a42dd3aca5..b8c174bfa57f3 100644 --- a/tests/phpstan/baselines/class.notFound.neon +++ b/tests/phpstan/baselines/class.notFound.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=class.notFound # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/deadCode.unreachable.neon b/tests/phpstan/baselines/deadCode.unreachable.neon index 3dccb140aacc0..734e4a92777a4 100644 --- a/tests/phpstan/baselines/deadCode.unreachable.neon +++ b/tests/phpstan/baselines/deadCode.unreachable.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=deadCode.unreachable # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/empty.property.neon b/tests/phpstan/baselines/empty.property.neon index 869cadbf2fea7..5a159fcad27f9 100644 --- a/tests/phpstan/baselines/empty.property.neon +++ b/tests/phpstan/baselines/empty.property.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=empty.property # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/empty.variable.neon b/tests/phpstan/baselines/empty.variable.neon index fe2adb8dec11e..ee989660e6077 100644 --- a/tests/phpstan/baselines/empty.variable.neon +++ b/tests/phpstan/baselines/empty.variable.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=empty.variable # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/function.alreadyNarrowedType.neon b/tests/phpstan/baselines/function.alreadyNarrowedType.neon index 467991720b5a7..c9d228878b7bb 100644 --- a/tests/phpstan/baselines/function.alreadyNarrowedType.neon +++ b/tests/phpstan/baselines/function.alreadyNarrowedType.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=function.alreadyNarrowedType # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/function.resultUnused.neon b/tests/phpstan/baselines/function.resultUnused.neon index 442b207fe196d..9cd676e4868da 100644 --- a/tests/phpstan/baselines/function.resultUnused.neon +++ b/tests/phpstan/baselines/function.resultUnused.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=function.resultUnused # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/identical.alwaysFalse.neon b/tests/phpstan/baselines/identical.alwaysFalse.neon index 5bd777f130a40..fc6206b269207 100644 --- a/tests/phpstan/baselines/identical.alwaysFalse.neon +++ b/tests/phpstan/baselines/identical.alwaysFalse.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=identical.alwaysFalse # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/if.alwaysFalse.neon b/tests/phpstan/baselines/if.alwaysFalse.neon index 30fb317dec4c4..ab1be1643ca15 100644 --- a/tests/phpstan/baselines/if.alwaysFalse.neon +++ b/tests/phpstan/baselines/if.alwaysFalse.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=if.alwaysFalse # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/if.alwaysTrue.neon b/tests/phpstan/baselines/if.alwaysTrue.neon index 1d3af11e446fb..7a9176e76e882 100644 --- a/tests/phpstan/baselines/if.alwaysTrue.neon +++ b/tests/phpstan/baselines/if.alwaysTrue.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=if.alwaysTrue # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/isset.property.neon b/tests/phpstan/baselines/isset.property.neon index 327cd1c76aa43..4c3d7ee713dfe 100644 --- a/tests/phpstan/baselines/isset.property.neon +++ b/tests/phpstan/baselines/isset.property.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=isset.property # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/method.childParameterType.neon b/tests/phpstan/baselines/method.childParameterType.neon index 4c68bab982fab..87ab2c366a862 100644 --- a/tests/phpstan/baselines/method.childParameterType.neon +++ b/tests/phpstan/baselines/method.childParameterType.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=method.childParameterType # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/method.unused.neon b/tests/phpstan/baselines/method.unused.neon index 054dc94542241..48a5875ba724c 100644 --- a/tests/phpstan/baselines/method.unused.neon +++ b/tests/phpstan/baselines/method.unused.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=method.unused # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/notIdentical.alwaysTrue.neon b/tests/phpstan/baselines/notIdentical.alwaysTrue.neon index 1a6284b361ec2..0784522ea0cac 100644 --- a/tests/phpstan/baselines/notIdentical.alwaysTrue.neon +++ b/tests/phpstan/baselines/notIdentical.alwaysTrue.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=notIdentical.alwaysTrue # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon b/tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon index 6ea0acc46ac2b..65e84f4cb8f85 100644 --- a/tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon +++ b/tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=offsetAccess.nonOffsetAccessible # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/offsetAccess.notFound.neon b/tests/phpstan/baselines/offsetAccess.notFound.neon index ed127f9ed48cd..db24bcd252e66 100644 --- a/tests/phpstan/baselines/offsetAccess.notFound.neon +++ b/tests/phpstan/baselines/offsetAccess.notFound.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=offsetAccess.notFound # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/offsetAssign.valueType.neon b/tests/phpstan/baselines/offsetAssign.valueType.neon index 6764804f6d4f1..661940b701cdc 100644 --- a/tests/phpstan/baselines/offsetAssign.valueType.neon +++ b/tests/phpstan/baselines/offsetAssign.valueType.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=offsetAssign.valueType # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/parameterByRef.type.neon b/tests/phpstan/baselines/parameterByRef.type.neon index 40c8748b45974..1c4df7cf6052f 100644 --- a/tests/phpstan/baselines/parameterByRef.type.neon +++ b/tests/phpstan/baselines/parameterByRef.type.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=parameterByRef.type # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/parameterByRef.unusedType.neon b/tests/phpstan/baselines/parameterByRef.unusedType.neon index 0704b43af2e54..4cad23881bdbc 100644 --- a/tests/phpstan/baselines/parameterByRef.unusedType.neon +++ b/tests/phpstan/baselines/parameterByRef.unusedType.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=parameterByRef.unusedType # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/property.defaultValue.neon b/tests/phpstan/baselines/property.defaultValue.neon index 6cda21d8d6b20..159831865f8db 100644 --- a/tests/phpstan/baselines/property.defaultValue.neon +++ b/tests/phpstan/baselines/property.defaultValue.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=property.defaultValue # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/property.nonObject.neon b/tests/phpstan/baselines/property.nonObject.neon index e9f1ae8ec3d98..99c1a0d6ef95f 100644 --- a/tests/phpstan/baselines/property.nonObject.neon +++ b/tests/phpstan/baselines/property.nonObject.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=property.nonObject # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/property.notFound.neon b/tests/phpstan/baselines/property.notFound.neon index a3f3247ffce3e..590b386ccdc88 100644 --- a/tests/phpstan/baselines/property.notFound.neon +++ b/tests/phpstan/baselines/property.notFound.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=property.notFound # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/property.private.neon b/tests/phpstan/baselines/property.private.neon index 20fdc0268cef3..96f94e58393d6 100644 --- a/tests/phpstan/baselines/property.private.neon +++ b/tests/phpstan/baselines/property.private.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=property.private # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/return.type.neon b/tests/phpstan/baselines/return.type.neon index f0f524e3f0dbd..2b96ac82ae8a3 100644 --- a/tests/phpstan/baselines/return.type.neon +++ b/tests/phpstan/baselines/return.type.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=return.type # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/varTag.noVariable.neon b/tests/phpstan/baselines/varTag.noVariable.neon index 2593db2cafcd1..216fc24f2c404 100644 --- a/tests/phpstan/baselines/varTag.noVariable.neon +++ b/tests/phpstan/baselines/varTag.noVariable.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=varTag.noVariable # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/baselines/variable.undefined.neon b/tests/phpstan/baselines/variable.undefined.neon index b1eec349cd4d0..663cfe1402f54 100644 --- a/tests/phpstan/baselines/variable.undefined.neon +++ b/tests/phpstan/baselines/variable.undefined.neon @@ -9,11 +9,11 @@ # # The goal is to empty this file and delete it. # -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with +# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=variable.undefined # -# which reruns the analysis with the baselines in this directory suppressed, so +# This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. parameters: diff --git a/tests/phpstan/generate-baselines.php b/tests/phpstan/generate-baselines.php index 1383da617750f..7047c1d19c067 100644 --- a/tests/phpstan/generate-baselines.php +++ b/tests/phpstan/generate-baselines.php @@ -912,11 +912,11 @@ function build_baseline_header( string $identifier, string $options = '' ): stri # # The goal is to empty this file and delete it. # - # Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with + # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # # composer phpstan:baselines -- --identifier=$identifier$options # - # which reruns the analysis with the baselines in this directory suppressed, so + # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. TEXT; From 8ecdd5df8b3cc5f3d27a8713ffa3629265caefde Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 22:26:10 -0800 Subject: [PATCH 18/30] Build/Test Tools: Name the configuration including the other in the PHPStan 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpstan/README.md b/tests/phpstan/README.md index 6efa32fb159f7..375721e6e33ac 100644 --- a/tests/phpstan/README.md +++ b/tests/phpstan/README.md @@ -112,7 +112,7 @@ parameters: `phpstan.neon.dist` holds the whole codebase to a low rule level, since most of it does not yet meet a higher one. Some of it already does, mostly code added in recent releases, such as the AI client and the Abilities API. [`phpstan-strict.neon.dist`](../../phpstan-strict.neon.dist) holds those paths to a stricter rule level, currently 10, so that they keep meeting it. The level is set as a number rather than `max`, so that it is only raised deliberately, not by a PHPStan update adding a level. -It includes `phpstan.neon.dist`, so everything that enforces still applies, and replaces the paths analyzed with the ones it lists under `paths!`. The rest of core is scanned instead, so that what those paths use is known. A scanned file gets the same [WordPress-specific extensions](#wordpress-specific-extensions) as an analyzed one, because `base.neon` has every parse run them, so the types of the code outside the strict paths are the same as in the analysis of the whole codebase. +`phpstan-strict.neon.dist` includes `phpstan.neon.dist`, so everything `phpstan.neon.dist` enforces still applies, and replaces the paths analyzed with the ones it lists under `paths!`. The rest of core is scanned instead, so that what those paths use is known. A scanned file gets the same [WordPress-specific extensions](#wordpress-specific-extensions) as an analyzed one, because `base.neon` has every parse run them, so the types of the code outside the strict paths are the same as in the analysis of the whole codebase. Errors are baselined in two layers. An error that the analysis of the whole codebase reports is baselined in [`baselines/`](baselines), as usual, and stays baselined there for the strict analysis. What the stricter level adds in the strict paths is baselined in [`baselines-strict/`](baselines-strict), in the same way, and included through its own [`loader.php`](baselines-strict/loader.php). `composer phpstan:baselines` and `composer phpstan:fix` maintain both. From 7bdd35bf6393d7ed5b9847946738787e19cba378 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 22:32:33 -0800 Subject: [PATCH 19/30] Build/Test Tools: Quote the paths in the command regenerating a PHPStan 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/generate-baselines.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/phpstan/generate-baselines.php b/tests/phpstan/generate-baselines.php index 7047c1d19c067..1e295800fd043 100644 --- a/tests/phpstan/generate-baselines.php +++ b/tests/phpstan/generate-baselines.php @@ -480,10 +480,10 @@ static function () use ( $temp_config, $temp_baseline ): void { */ $regenerate_options = ''; if ( DEFAULT_CONFIG !== $config_relative ) { - $regenerate_options .= ' --config=' . $config_option; + $regenerate_options .= ' --config=' . quote_shell_value( $config_option ); } if ( $config_output_dir !== trim( normalize_path( $output_option ), '/' ) ) { - $regenerate_options .= ' --output-dir=' . $output_option; + $regenerate_options .= ' --output-dir=' . quote_shell_value( $output_option ); } foreach ( $grouped as $identifier => $entries ) { @@ -890,6 +890,22 @@ function quote_neon_value( string $value ): string { return "'" . str_replace( "'", "''", $value ) . "'"; } +/** + * Quotes a value for a command shown to be run in a shell, where it needs it. + * + * The command is only written into a baseline's header, to be copied from there, + * so a value is left as it is when the shell would read it that way, as the paths + * of the default configurations and their directories are. Any other value, such + * as a path with a space in it, is quoted, so the copied command still passes it + * as one argument. + * + * @param string $value Value to quote. + * @return string Value, quoted if the shell would otherwise split or expand it. + */ +function quote_shell_value( string $value ): string { + return 1 === preg_match( '#^[\w./-]+$#', $value ) ? $value : escapeshellarg( $value ); +} + /** * Builds the header comment for a per-identifier baseline. * From 0d9d9ca2a61309fbbc0f656938dc8919c363f4d6 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 22:32:46 -0800 Subject: [PATCH 20/30] Build/Test Tools: Rewrap a comment in the PHPStan baseline generator. 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/generate-baselines.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpstan/generate-baselines.php b/tests/phpstan/generate-baselines.php index 1e295800fd043..13396e9674ff9 100644 --- a/tests/phpstan/generate-baselines.php +++ b/tests/phpstan/generate-baselines.php @@ -414,9 +414,9 @@ static function () use ( $temp_config, $temp_baseline ): void { * PHPStan inherits it, as do the worker processes it starts. It is the real path, * since that is what the loader's __DIR__ is. An output directory that does not * exist, which only `--combined` leaves uncreated, holds no loader to match, so it - * is not set at all then. It is cleared first - * either way, so that a value exported in the shell, perhaps naming another - * directory, cannot switch off baselines this run means to keep. + * is not set at all then. It is cleared first either way, so that a value + * exported in the shell, perhaps naming another directory, cannot switch off + * baselines this run means to keep. */ putenv( GENERATING_BASELINES_ENV ); $resolved_output_dir = realpath( $output_dir ); From 628ded63accc549493ba4ef8af39fa4e3498cf3d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 22:38:38 -0800 Subject: [PATCH 21/30] Build/Test Tools: Skip an option's value without index arithmetic in 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/analyse.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/phpstan/analyse.php b/tests/phpstan/analyse.php index 608dab268ff4b..17f140ff73e0a 100644 --- a/tests/phpstan/analyse.php +++ b/tests/phpstan/analyse.php @@ -215,7 +215,7 @@ function is_level_at_least( string $level, string $minimum ): bool { * `--fix-ignored`, and the paths to analyze. An option's value can follow it as the * next argument, so that is skipped rather than taken for a path. * - * @param string[] $args Arguments. + * @param list $args Arguments. * @return string|null Description of the first such argument, or null if there is none. */ function get_single_analysis_reason( array $args ): ?string { @@ -223,12 +223,16 @@ function get_single_analysis_reason( array $args ): ?string { $takes_value = array( '-c', '--configuration', '-l', '--level', '-a', '--autoload-file', '--error-format', '--memory-limit', '--tmp-file', '--instead-of' ); $single = array( '-c', '--configuration', '-l', '--level', '--error-format', '--generate-baseline', '-b', '--fix-ignored' ); - $count = count( $args ); - for ( $i = 0; $i < $count; $i++ ) { - $arg = $args[ $i ]; + $is_value = false; + foreach ( $args as $i => $arg ) { + // The value of the option before, given as an argument of its own. + if ( $is_value ) { + $is_value = false; + continue; + } if ( '--' === $arg ) { - return $i + 1 < $count ? 'the paths given' : null; + return $i + 1 < count( $args ) ? 'the paths given' : null; } if ( '' === $arg || '-' !== $arg[0] ) { @@ -249,7 +253,7 @@ function get_single_analysis_reason( array $args ): ?string { } if ( ! $has_value && in_array( $name, $takes_value, true ) ) { - ++$i; + $is_value = true; } } From ff28f2dd91b16df7e50244a067b3cc5827eb7afa Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 22:40:13 -0800 Subject: [PATCH 22/30] Build/Test Tools: Check whether PHPStan could dump a configuration's 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/analyse.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/phpstan/analyse.php b/tests/phpstan/analyse.php index 17f140ff73e0a..ea2cf53dcf5ad 100644 --- a/tests/phpstan/analyse.php +++ b/tests/phpstan/analyse.php @@ -178,6 +178,11 @@ function get_level( string $phpstan, string $config ): ?string { $exit_code = 0; exec( sprintf( '%s %s dump-parameters --configuration=%s --json 2>/dev/null', escapeshellarg( PHP_BINARY ), escapeshellarg( $phpstan ), escapeshellarg( $config ) ), $output, $exit_code ); + // A configuration PHPStan cannot load, for one, leaves no parameters to read. + if ( 0 !== $exit_code ) { + return null; + } + foreach ( $output as $line ) { if ( 1 === preg_match( '/^\s*"level": ("max"|"?\d+"?),?$/', $line, $matches ) ) { return trim( $matches[1], '"' ); From 20f269a66297501ec2f29e108530b0be1faab0a0 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 22:41:31 -0800 Subject: [PATCH 23/30] Build/Test Tools: Allow any whitespace after the key of a dumped PHPStan 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- .github/workflows/reusable-phpstan-static-analysis-v1.yml | 2 +- tests/phpstan/analyse.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/reusable-phpstan-static-analysis-v1.yml b/.github/workflows/reusable-phpstan-static-analysis-v1.yml index 608b378da89fc..aba7162bb2a05 100644 --- a/.github/workflows/reusable-phpstan-static-analysis-v1.yml +++ b/.github/workflows/reusable-phpstan-static-analysis-v1.yml @@ -179,7 +179,7 @@ jobs: [ 'dump-parameters', `--configuration=${ process.env.CONFIG }`, '--json' ], { encoding: 'utf8' } ); - const match = parameters.match( /^\s*"level": "?(max|\d+)"?,?$/m ); + const match = parameters.match( /^\s*"level":\s*"?(max|\d+)"?,?$/m ); if ( match ) { level = match[ 1 ] === 'max' ? 'max' : Number( match[ 1 ] ); } diff --git a/tests/phpstan/analyse.php b/tests/phpstan/analyse.php index ea2cf53dcf5ad..cdcbdb107fe98 100644 --- a/tests/phpstan/analyse.php +++ b/tests/phpstan/analyse.php @@ -184,7 +184,7 @@ function get_level( string $phpstan, string $config ): ?string { } foreach ( $output as $line ) { - if ( 1 === preg_match( '/^\s*"level": ("max"|"?\d+"?),?$/', $line, $matches ) ) { + if ( 1 === preg_match( '/^\s*"level":\s*("max"|"?\d+"?),?$/', $line, $matches ) ) { return trim( $matches[1], '"' ); } } From 3e927df0269ec2535ec758ab0ac9331b7ee15938 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 22:45:34 -0800 Subject: [PATCH 24/30] Build/Test Tools: Run PHPStan's `analyse` command through a function 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/analyse.php | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/phpstan/analyse.php b/tests/phpstan/analyse.php index cdcbdb107fe98..6bdb8538425d1 100644 --- a/tests/phpstan/analyse.php +++ b/tests/phpstan/analyse.php @@ -87,12 +87,12 @@ exit( 1 ); } fwrite( STDERR, "Running a single analysis, because of $single_reason.\n" ); - exit( run( 'Analyzing', $phpstan, $args ) ); + exit( analyse( 'Analyzing', $phpstan, $args ) ); } if ( $fix ) { foreach ( array( PROJECT_CONFIG, STRICT_CONFIG ) as $config ) { - $status = run( "Fixing with $config", $phpstan, array_merge( array( "--configuration=$config", '--fix' ), $args ) ); + $status = analyse( "Fixing with $config", $phpstan, array_merge( array( "--configuration=$config", '--fix' ), $args ) ); // PHPStan exits with 1 both when it fixed something and when there was nothing to fix. if ( $status > 1 ) { @@ -100,14 +100,14 @@ } } - $status = run( 'Deleting the baselines left without entries', __DIR__ . '/generate-baselines.php', array( '--prune' ), false ); + $status = run( 'Deleting the baselines left without entries', __DIR__ . '/generate-baselines.php', array( '--prune' ) ); if ( 0 !== $status ) { exit( $status ); } $exit_code = 0; foreach ( array( PROJECT_CONFIG, STRICT_CONFIG ) as $config ) { - $exit_code = max( $exit_code, run( "Analyzing with $config", $phpstan, array_merge( array( "--configuration=$config" ), $args ) ) ); + $exit_code = max( $exit_code, analyse( "Analyzing with $config", $phpstan, array_merge( array( "--configuration=$config" ), $args ) ) ); } exit( $exit_code ); } @@ -116,7 +116,7 @@ $strict_config = is_file( $repo_root . '/phpstan-strict.neon' ) ? 'phpstan-strict.neon' : STRICT_CONFIG; // PHPStan reads phpstan.neon in place of phpstan.neon.dist by itself, so the first analysis names neither. -$exit_code = run( 'Analyzing with ' . ( is_file( $local_config ) ? 'phpstan.neon' : PROJECT_CONFIG ), $phpstan, $args ); +$exit_code = analyse( 'Analyzing with ' . ( is_file( $local_config ) ? 'phpstan.neon' : PROJECT_CONFIG ), $phpstan, $args ); if ( is_file( $local_config ) ) { $local_level = get_level( $phpstan, $local_config ); @@ -128,7 +128,7 @@ } } -exit( max( $exit_code, run( "Analyzing the strict paths with $strict_config", $phpstan, array_merge( array( "--configuration=$strict_config" ), $args ) ) ) ); +exit( max( $exit_code, analyse( "Analyzing the strict paths with $strict_config", $phpstan, array_merge( array( "--configuration=$strict_config" ), $args ) ) ) ); /** * Runs a command with a heading, passing its output through. @@ -139,19 +139,15 @@ * The script runs on the PHP running this one, which Composer's `@php` chose, * rather than on whichever `php` the script's shebang finds first. * - * @param string $heading Heading describing the run. - * @param string $script Path to the PHP script to run. - * @param string[] $args Arguments, which are escaped for the shell here. - * @param bool $is_analysis Whether the script is PHPStan, to which `analyse` is passed first. + * @param string $heading Heading describing the run. + * @param string $script Path to the PHP script to run. + * @param string[] $args Arguments, which are escaped for the shell here. * @return int Exit status of the script. */ -function run( string $heading, string $script, array $args, bool $is_analysis = true ): int { +function run( string $heading, string $script, array $args ): int { fwrite( STDERR, "\n== $heading ==\n\n" ); $parts = array( escapeshellarg( PHP_BINARY ), escapeshellarg( $script ) ); - if ( $is_analysis ) { - $parts[] = 'analyse'; - } foreach ( $args as $arg ) { $parts[] = escapeshellarg( $arg ); } @@ -162,6 +158,18 @@ function run( string $heading, string $script, array $args, bool $is_analysis = return $exit_code; } +/** + * Runs PHPStan's `analyse` command with a heading, passing its output through. + * + * @param string $heading Heading describing the run. + * @param string $phpstan Path to the PHPStan executable. + * @param string[] $args Arguments to the command, which are escaped for the shell. + * @return int Exit status of PHPStan. + */ +function analyse( string $heading, string $phpstan, array $args ): int { + return run( $heading, $phpstan, array_merge( array( 'analyse' ), $args ) ); +} + /** * Gets the rule level a configuration analyzes at. * From e069ef27dc8557e795b144e212730b76817ad958 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 22:55:42 -0800 Subject: [PATCH 25/30] Build/Test Tools: Unpack the arguments after PHPStan's `analyse` command. `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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/analyse.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpstan/analyse.php b/tests/phpstan/analyse.php index 6bdb8538425d1..bbbb88a5cf60c 100644 --- a/tests/phpstan/analyse.php +++ b/tests/phpstan/analyse.php @@ -161,13 +161,13 @@ function run( string $heading, string $script, array $args ): int { /** * Runs PHPStan's `analyse` command with a heading, passing its output through. * - * @param string $heading Heading describing the run. - * @param string $phpstan Path to the PHPStan executable. - * @param string[] $args Arguments to the command, which are escaped for the shell. + * @param string $heading Heading describing the run. + * @param string $phpstan Path to the PHPStan executable. + * @param list $args Arguments to the command, which are escaped for the shell. * @return int Exit status of PHPStan. */ function analyse( string $heading, string $phpstan, array $args ): int { - return run( $heading, $phpstan, array_merge( array( 'analyse' ), $args ) ); + return run( $heading, $phpstan, array( 'analyse', ...$args ) ); } /** From 6428c6152acec396034c2c3fef240e9fbd5eeb9f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 23:15:39 -0800 Subject: [PATCH 26/30] Build/Test Tools: Run PHPStan on pull requests changing only the strict 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- .github/workflows/phpstan-static-analysis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/phpstan-static-analysis.yml b/.github/workflows/phpstan-static-analysis.yml index f0eaad6d015f3..3d855296e0e0a 100644 --- a/.github/workflows/phpstan-static-analysis.yml +++ b/.github/workflows/phpstan-static-analysis.yml @@ -17,8 +17,10 @@ on: - 'composer.*' # These files configure PHPStan. Changes could affect the outcome. - 'phpstan.neon.dist' + - 'phpstan-strict.neon.dist' - 'tests/phpstan/base.neon' - 'tests/phpstan/baselines/**' + - 'tests/phpstan/baselines-strict/**' # Confirm any changes to relevant workflow files. - '.github/workflows/phpstan-static-analysis.yml' - '.github/workflows/reusable-phpstan-static-analysis-v1.yml' From aff84be3088a814c0204fe0a24cd66673377c3ac Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 23:16:00 -0800 Subject: [PATCH 27/30] Build/Test Tools: Lift Composer's timeout for each single PHPStan analysis. `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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3379966cf8cee..f17e0922e00d1 100644 --- a/composer.json +++ b/composer.json @@ -76,8 +76,8 @@ }, "scripts": { "phpstan": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpstan/analyse.php --memory-limit=2G" ], - "phpstan:default": "@php ./vendor/bin/phpstan analyse --configuration=phpstan.neon.dist --memory-limit=2G", - "phpstan:strict": "@php ./vendor/bin/phpstan analyse --configuration=phpstan-strict.neon.dist --memory-limit=2G", + "phpstan:default": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/bin/phpstan analyse --configuration=phpstan.neon.dist --memory-limit=2G" ], + "phpstan:strict": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/bin/phpstan analyse --configuration=phpstan-strict.neon.dist --memory-limit=2G" ], "phpstan:baselines": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpstan/generate-baselines.php" ], "phpstan:fix": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpstan/analyse.php --memory-limit=2G --fix" ], "compat": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --standard=phpcompat.xml.dist --report=summary,source", From 246e1472726ee8656a8d48aaa3528cc892dbb682 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 23:16:36 -0800 Subject: [PATCH 28/30] Build/Test Tools: Name the configuration in every command regenerating 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/baselines/argument.type.neon | 2 +- .../baselines/argument.unresolvableType.neon | 2 +- tests/phpstan/baselines/assign.propertyType.neon | 2 +- tests/phpstan/baselines/binaryOp.invalid.neon | 2 +- .../baselines/booleanAnd.leftAlwaysTrue.neon | 2 +- tests/phpstan/baselines/booleanNot.alwaysTrue.neon | 2 +- tests/phpstan/baselines/class.notFound.neon | 2 +- tests/phpstan/baselines/deadCode.unreachable.neon | 2 +- tests/phpstan/baselines/empty.property.neon | 2 +- tests/phpstan/baselines/empty.variable.neon | 2 +- .../baselines/function.alreadyNarrowedType.neon | 2 +- tests/phpstan/baselines/function.resultUnused.neon | 2 +- tests/phpstan/baselines/identical.alwaysFalse.neon | 2 +- tests/phpstan/baselines/if.alwaysFalse.neon | 2 +- tests/phpstan/baselines/if.alwaysTrue.neon | 2 +- tests/phpstan/baselines/isset.property.neon | 2 +- .../baselines/method.childParameterType.neon | 2 +- tests/phpstan/baselines/method.unused.neon | 2 +- .../phpstan/baselines/notIdentical.alwaysTrue.neon | 2 +- .../offsetAccess.nonOffsetAccessible.neon | 2 +- tests/phpstan/baselines/offsetAccess.notFound.neon | 2 +- .../phpstan/baselines/offsetAssign.valueType.neon | 2 +- tests/phpstan/baselines/parameterByRef.type.neon | 2 +- .../baselines/parameterByRef.unusedType.neon | 2 +- tests/phpstan/baselines/property.defaultValue.neon | 2 +- tests/phpstan/baselines/property.nonObject.neon | 2 +- tests/phpstan/baselines/property.notFound.neon | 2 +- tests/phpstan/baselines/property.private.neon | 2 +- tests/phpstan/baselines/return.type.neon | 2 +- tests/phpstan/baselines/varTag.noVariable.neon | 2 +- tests/phpstan/baselines/variable.undefined.neon | 2 +- tests/phpstan/generate-baselines.php | 14 ++++++-------- 32 files changed, 37 insertions(+), 39 deletions(-) diff --git a/tests/phpstan/baselines/argument.type.neon b/tests/phpstan/baselines/argument.type.neon index 6427acb3e2a01..bd6828d096b11 100644 --- a/tests/phpstan/baselines/argument.type.neon +++ b/tests/phpstan/baselines/argument.type.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=argument.type +# composer phpstan:baselines -- --identifier=argument.type --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/argument.unresolvableType.neon b/tests/phpstan/baselines/argument.unresolvableType.neon index f837a9dcb3560..f6ca492a525ce 100644 --- a/tests/phpstan/baselines/argument.unresolvableType.neon +++ b/tests/phpstan/baselines/argument.unresolvableType.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=argument.unresolvableType +# composer phpstan:baselines -- --identifier=argument.unresolvableType --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/assign.propertyType.neon b/tests/phpstan/baselines/assign.propertyType.neon index a0aebabe9f5cd..a9a89163f9df1 100644 --- a/tests/phpstan/baselines/assign.propertyType.neon +++ b/tests/phpstan/baselines/assign.propertyType.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=assign.propertyType +# composer phpstan:baselines -- --identifier=assign.propertyType --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/binaryOp.invalid.neon b/tests/phpstan/baselines/binaryOp.invalid.neon index a294ec62ed775..bfcd43d16d874 100644 --- a/tests/phpstan/baselines/binaryOp.invalid.neon +++ b/tests/phpstan/baselines/binaryOp.invalid.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=binaryOp.invalid +# composer phpstan:baselines -- --identifier=binaryOp.invalid --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon b/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon index 6cf262ecf88d6..1f55c01be4124 100644 --- a/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon +++ b/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=booleanAnd.leftAlwaysTrue +# composer phpstan:baselines -- --identifier=booleanAnd.leftAlwaysTrue --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/booleanNot.alwaysTrue.neon b/tests/phpstan/baselines/booleanNot.alwaysTrue.neon index 1fe2aefba14d0..7db8291d66e7c 100644 --- a/tests/phpstan/baselines/booleanNot.alwaysTrue.neon +++ b/tests/phpstan/baselines/booleanNot.alwaysTrue.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=booleanNot.alwaysTrue +# composer phpstan:baselines -- --identifier=booleanNot.alwaysTrue --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/class.notFound.neon b/tests/phpstan/baselines/class.notFound.neon index b8c174bfa57f3..97a6745e87a0d 100644 --- a/tests/phpstan/baselines/class.notFound.neon +++ b/tests/phpstan/baselines/class.notFound.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=class.notFound +# composer phpstan:baselines -- --identifier=class.notFound --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/deadCode.unreachable.neon b/tests/phpstan/baselines/deadCode.unreachable.neon index 734e4a92777a4..1a688f51c78a1 100644 --- a/tests/phpstan/baselines/deadCode.unreachable.neon +++ b/tests/phpstan/baselines/deadCode.unreachable.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=deadCode.unreachable +# composer phpstan:baselines -- --identifier=deadCode.unreachable --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/empty.property.neon b/tests/phpstan/baselines/empty.property.neon index 5a159fcad27f9..29c45b3128ea4 100644 --- a/tests/phpstan/baselines/empty.property.neon +++ b/tests/phpstan/baselines/empty.property.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=empty.property +# composer phpstan:baselines -- --identifier=empty.property --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/empty.variable.neon b/tests/phpstan/baselines/empty.variable.neon index ee989660e6077..47f6187fd5310 100644 --- a/tests/phpstan/baselines/empty.variable.neon +++ b/tests/phpstan/baselines/empty.variable.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=empty.variable +# composer phpstan:baselines -- --identifier=empty.variable --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/function.alreadyNarrowedType.neon b/tests/phpstan/baselines/function.alreadyNarrowedType.neon index c9d228878b7bb..3c1a44fe8f871 100644 --- a/tests/phpstan/baselines/function.alreadyNarrowedType.neon +++ b/tests/phpstan/baselines/function.alreadyNarrowedType.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=function.alreadyNarrowedType +# composer phpstan:baselines -- --identifier=function.alreadyNarrowedType --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/function.resultUnused.neon b/tests/phpstan/baselines/function.resultUnused.neon index 9cd676e4868da..045ad4b731459 100644 --- a/tests/phpstan/baselines/function.resultUnused.neon +++ b/tests/phpstan/baselines/function.resultUnused.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=function.resultUnused +# composer phpstan:baselines -- --identifier=function.resultUnused --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/identical.alwaysFalse.neon b/tests/phpstan/baselines/identical.alwaysFalse.neon index fc6206b269207..0d305bff88893 100644 --- a/tests/phpstan/baselines/identical.alwaysFalse.neon +++ b/tests/phpstan/baselines/identical.alwaysFalse.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=identical.alwaysFalse +# composer phpstan:baselines -- --identifier=identical.alwaysFalse --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/if.alwaysFalse.neon b/tests/phpstan/baselines/if.alwaysFalse.neon index ab1be1643ca15..ed8b9f60e0c1c 100644 --- a/tests/phpstan/baselines/if.alwaysFalse.neon +++ b/tests/phpstan/baselines/if.alwaysFalse.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=if.alwaysFalse +# composer phpstan:baselines -- --identifier=if.alwaysFalse --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/if.alwaysTrue.neon b/tests/phpstan/baselines/if.alwaysTrue.neon index 7a9176e76e882..a86c1b801ab98 100644 --- a/tests/phpstan/baselines/if.alwaysTrue.neon +++ b/tests/phpstan/baselines/if.alwaysTrue.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=if.alwaysTrue +# composer phpstan:baselines -- --identifier=if.alwaysTrue --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/isset.property.neon b/tests/phpstan/baselines/isset.property.neon index 4c3d7ee713dfe..4cf68462ad846 100644 --- a/tests/phpstan/baselines/isset.property.neon +++ b/tests/phpstan/baselines/isset.property.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=isset.property +# composer phpstan:baselines -- --identifier=isset.property --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/method.childParameterType.neon b/tests/phpstan/baselines/method.childParameterType.neon index 87ab2c366a862..5faf12a73aa86 100644 --- a/tests/phpstan/baselines/method.childParameterType.neon +++ b/tests/phpstan/baselines/method.childParameterType.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=method.childParameterType +# composer phpstan:baselines -- --identifier=method.childParameterType --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/method.unused.neon b/tests/phpstan/baselines/method.unused.neon index 48a5875ba724c..ced0e2372a23f 100644 --- a/tests/phpstan/baselines/method.unused.neon +++ b/tests/phpstan/baselines/method.unused.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=method.unused +# composer phpstan:baselines -- --identifier=method.unused --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/notIdentical.alwaysTrue.neon b/tests/phpstan/baselines/notIdentical.alwaysTrue.neon index 0784522ea0cac..642d685217d02 100644 --- a/tests/phpstan/baselines/notIdentical.alwaysTrue.neon +++ b/tests/phpstan/baselines/notIdentical.alwaysTrue.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=notIdentical.alwaysTrue +# composer phpstan:baselines -- --identifier=notIdentical.alwaysTrue --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon b/tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon index 65e84f4cb8f85..ed021ec794760 100644 --- a/tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon +++ b/tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=offsetAccess.nonOffsetAccessible +# composer phpstan:baselines -- --identifier=offsetAccess.nonOffsetAccessible --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/offsetAccess.notFound.neon b/tests/phpstan/baselines/offsetAccess.notFound.neon index db24bcd252e66..9f61db04aba25 100644 --- a/tests/phpstan/baselines/offsetAccess.notFound.neon +++ b/tests/phpstan/baselines/offsetAccess.notFound.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=offsetAccess.notFound +# composer phpstan:baselines -- --identifier=offsetAccess.notFound --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/offsetAssign.valueType.neon b/tests/phpstan/baselines/offsetAssign.valueType.neon index 661940b701cdc..8077ca9892ff4 100644 --- a/tests/phpstan/baselines/offsetAssign.valueType.neon +++ b/tests/phpstan/baselines/offsetAssign.valueType.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=offsetAssign.valueType +# composer phpstan:baselines -- --identifier=offsetAssign.valueType --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/parameterByRef.type.neon b/tests/phpstan/baselines/parameterByRef.type.neon index 1c4df7cf6052f..0a99ae46d6d27 100644 --- a/tests/phpstan/baselines/parameterByRef.type.neon +++ b/tests/phpstan/baselines/parameterByRef.type.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=parameterByRef.type +# composer phpstan:baselines -- --identifier=parameterByRef.type --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/parameterByRef.unusedType.neon b/tests/phpstan/baselines/parameterByRef.unusedType.neon index 4cad23881bdbc..4738b39636023 100644 --- a/tests/phpstan/baselines/parameterByRef.unusedType.neon +++ b/tests/phpstan/baselines/parameterByRef.unusedType.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=parameterByRef.unusedType +# composer phpstan:baselines -- --identifier=parameterByRef.unusedType --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/property.defaultValue.neon b/tests/phpstan/baselines/property.defaultValue.neon index 159831865f8db..5c7ebe5274920 100644 --- a/tests/phpstan/baselines/property.defaultValue.neon +++ b/tests/phpstan/baselines/property.defaultValue.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=property.defaultValue +# composer phpstan:baselines -- --identifier=property.defaultValue --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/property.nonObject.neon b/tests/phpstan/baselines/property.nonObject.neon index 99c1a0d6ef95f..2acecd3a68838 100644 --- a/tests/phpstan/baselines/property.nonObject.neon +++ b/tests/phpstan/baselines/property.nonObject.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=property.nonObject +# composer phpstan:baselines -- --identifier=property.nonObject --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/property.notFound.neon b/tests/phpstan/baselines/property.notFound.neon index 590b386ccdc88..6686c06ba9431 100644 --- a/tests/phpstan/baselines/property.notFound.neon +++ b/tests/phpstan/baselines/property.notFound.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=property.notFound +# composer phpstan:baselines -- --identifier=property.notFound --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/property.private.neon b/tests/phpstan/baselines/property.private.neon index 96f94e58393d6..6d08652de08d5 100644 --- a/tests/phpstan/baselines/property.private.neon +++ b/tests/phpstan/baselines/property.private.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=property.private +# composer phpstan:baselines -- --identifier=property.private --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/return.type.neon b/tests/phpstan/baselines/return.type.neon index 2b96ac82ae8a3..9143cbd2bbad7 100644 --- a/tests/phpstan/baselines/return.type.neon +++ b/tests/phpstan/baselines/return.type.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=return.type +# composer phpstan:baselines -- --identifier=return.type --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/varTag.noVariable.neon b/tests/phpstan/baselines/varTag.noVariable.neon index 216fc24f2c404..5078f4df8beb9 100644 --- a/tests/phpstan/baselines/varTag.noVariable.neon +++ b/tests/phpstan/baselines/varTag.noVariable.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=varTag.noVariable +# composer phpstan:baselines -- --identifier=varTag.noVariable --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/baselines/variable.undefined.neon b/tests/phpstan/baselines/variable.undefined.neon index 663cfe1402f54..a46e0e5fa2283 100644 --- a/tests/phpstan/baselines/variable.undefined.neon +++ b/tests/phpstan/baselines/variable.undefined.neon @@ -11,7 +11,7 @@ # # Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: # -# composer phpstan:baselines -- --identifier=variable.undefined +# composer phpstan:baselines -- --identifier=variable.undefined --config=phpstan.neon.dist # # This reruns the analysis with the baselines in this directory suppressed, so # that their errors surface again, and rewrites only this file. diff --git a/tests/phpstan/generate-baselines.php b/tests/phpstan/generate-baselines.php index 13396e9674ff9..3611c958627cd 100644 --- a/tests/phpstan/generate-baselines.php +++ b/tests/phpstan/generate-baselines.php @@ -473,15 +473,13 @@ static function () use ( $temp_config, $temp_baseline ): void { /* * The command each header gives for regenerating its baseline has to name the - * configuration and the directory this run used, where they are not the - * defaults. Without them, it would regenerate the default directory instead. - * A default configuration's own directory needs no naming, since naming the - * configuration alone writes there. + * configuration this run used, even the default one, since without a + * configuration named, every one in DEFAULT_CONFIGS is processed, and the + * baselines of the same identifier in each of their directories are rewritten. + * The directory is only named where it is not the configuration's own, since + * naming the configuration alone writes there. */ -$regenerate_options = ''; -if ( DEFAULT_CONFIG !== $config_relative ) { - $regenerate_options .= ' --config=' . quote_shell_value( $config_option ); -} +$regenerate_options = ' --config=' . quote_shell_value( $config_option ); if ( $config_output_dir !== trim( normalize_path( $output_option ), '/' ) ) { $regenerate_options .= ' --output-dir=' . quote_shell_value( $output_option ); } From c5bc433bbf9a1c4b19e8e3a68733a0e8db583ee3 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 23:17:14 -0800 Subject: [PATCH 29/30] Build/Test Tools: Say what skipping the strict PHPStan analysis assumes. `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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- tests/phpstan/README.md | 2 +- tests/phpstan/analyse.php | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/phpstan/README.md b/tests/phpstan/README.md index 375721e6e33ac..056c4acdfb077 100644 --- a/tests/phpstan/README.md +++ b/tests/phpstan/README.md @@ -125,7 +125,7 @@ To hold another path to the stricter level: In the strict paths, **do not add an `@phpstan-ignore` comment for an error that only the stricter level reports**. The analysis of the whole codebase does not report that error, so it reports the comment as ignoring nothing, and `composer phpstan:fix` would remove it. Fix the error, or baseline it instead. -A local `phpstan-strict.neon` overrides `phpstan-strict.neon.dist`, the same way `phpstan.neon` overrides `phpstan.neon.dist`. When a local `phpstan.neon` already analyzes everything at the strict level or above, `composer phpstan` skips the second analysis, since it could only repeat part of the first. +A local `phpstan-strict.neon` overrides `phpstan-strict.neon.dist`, the same way `phpstan.neon` overrides `phpstan.neon.dist`. When a local `phpstan.neon` analyzes at the strict level or above, `composer phpstan` skips the second analysis, since it could only repeat part of the first. Only the levels are compared, so if the local `phpstan.neon` also narrows the paths analyzed, leaving out some of the strict paths, run `composer phpstan:strict` as well. For more information about configuring PHPStan, see the [PHPStan documentation's Config reference](https://phpstan.org/config-reference). diff --git a/tests/phpstan/analyse.php b/tests/phpstan/analyse.php index bbbb88a5cf60c..816198c483114 100644 --- a/tests/phpstan/analyse.php +++ b/tests/phpstan/analyse.php @@ -11,9 +11,11 @@ * Each analysis honors a local override of its configuration, the same way * PHPStan does: phpstan.neon in place of phpstan.neon.dist, which PHPStan finds by * itself, and phpstan-strict.neon in place of phpstan-strict.neon.dist, which - * this script chooses. When a local phpstan.neon already analyzes the whole - * codebase at the strict rule level or above, the second analysis could only - * repeat some of what the first reported, so it is skipped. + * this script chooses. When a local phpstan.neon analyzes at the strict rule + * level or above, the second analysis is skipped, since for the paths the first + * analyzed it could only repeat some of what that reported. Only the levels are + * compared, so a local phpstan.neon narrowing the paths it analyzes may leave + * strict paths out, which `composer phpstan:strict` still analyzes. * * With `--fix`, the stale entries of both sets of baselines are fixed instead, * along with anything else PHPStan can fix. That always uses the two .dist @@ -123,7 +125,7 @@ $strict_level = get_level( $phpstan, $repo_root . '/' . $strict_config ); if ( null !== $local_level && null !== $strict_level && is_level_at_least( $local_level, $strict_level ) ) { - fwrite( STDERR, "\nSkipping $strict_config: phpstan.neon already analyzes every path at level $local_level, and the strict paths are held to $strict_level.\n" ); + fwrite( STDERR, "\nSkipping $strict_config: phpstan.neon analyzes at level $local_level, and the strict paths are held to $strict_level. If phpstan.neon leaves any of them out, run `composer phpstan:strict` too.\n" ); exit( $exit_code ); } } From e1348eabcc5f18557a4262a1455b3757330d7675 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 17 Nov 2026 23:29:32 -0800 Subject: [PATCH 30/30] Build/Test Tools: Combine the files changed in the base branch from both 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) Claude-Session: https://claude.ai/code/session_01Tnky3Grhn8Rv7MidzhrtXU Claude-Code-Session-Id: d102d8d5-ffa7-4c14-add5-1e05d41fe751 --- .github/workflows/phpstan-pull-request-comments.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/phpstan-pull-request-comments.yml b/.github/workflows/phpstan-pull-request-comments.yml index d768ec9adc4b5..170d770cd880b 100644 --- a/.github/workflows/phpstan-pull-request-comments.yml +++ b/.github/workflows/phpstan-pull-request-comments.yml @@ -129,6 +129,7 @@ jobs: const expectsStrict = Array.isArray( results.analyses ) && results.analyses.includes( 'strict' ); let strictErrors = []; let strictLevel = null; + let strictChangedInBase = []; if ( expectsStrict ) { let strictResults = null; try { @@ -143,6 +144,7 @@ jobs: } strictLevel = asLevel( strictResults.level ); strictErrors = strictResults.errors.map( ( error ) => normalize( { ...error, analysis: 'strict', level: strictLevel } ) ); + strictChangedInBase = Array.isArray( strictResults.changed_in_base ) ? strictResults.changed_in_base : []; } // The strict analysis includes everything the default one does, so an error it reports at a lower level is @@ -226,7 +228,11 @@ jobs: // Files the base branch has changed since the pull request branched from it, in which the line numbers // reported can be off in the head commit, since the analysis ran on the head commit merged into the base. - const changedInBase = new Set( Array.isArray( results.changed_in_base ) ? results.changed_in_base.filter( ( file ) => typeof file === 'string' ) : [] ); + // Each analysis only lists those among the files it reported errors in, so the lists of both are combined. + const changedInBase = new Set( + [ ...( Array.isArray( results.changed_in_base ) ? results.changed_in_base : [] ), ...strictChangedInBase ] + .filter( ( file ) => typeof file === 'string' ) + ); const lineMayBeOff = ( error ) => ! error.fixed && Boolean( error.line ) && changedInBase.has( error.file ); const filesWithLinesOff = new Set( active.filter( lineMayBeOff ).map( ( error ) => error.file ) );