Add ResultCacheMetaExtension so the result cache tracks the Drupal site - #1030
Draft
mglaman wants to merge 1 commit into
Draft
Add ResultCacheMetaExtension so the result cache tracks the Drupal site#1030mglaman wants to merge 1 commit into
mglaman wants to merge 1 commit into
Conversation
mglaman
force-pushed
the
audit/5-result-cache
branch
from
August 5, 2026 16:20
3678ba5 to
6ee0ef6
Compare
mglaman
force-pushed
the
audit/5-result-cache
branch
from
August 5, 2026 16:44
6ee0ef6 to
e89c527
Compare
mglaman
force-pushed
the
audit/5-result-cache
branch
from
August 5, 2026 17:15
e89c527 to
206c73d
Compare
mglaman
force-pushed
the
audit/5-result-cache
branch
from
August 5, 2026 19:13
206c73d to
94480e0
Compare
PHPStan hashes its bootstrap files but knows nothing about the Drupal extensions, services.yml files, and config schemas the bootstrap discovers. Enabling a module, editing a services.yml, or upgrading core silently reused stale results from the cache. BootstrapResultCacheMetaExtension hashes the discovered extension inventory (info-file paths and content), every consumed services.yml, all config schema files, and the core version. Any change invalidates the whole result cache. The hashing runs once per analysis and covers a few hundred small YAML files, well under 50ms. ServiceMap now records which services.yml paths it consumed (new optional parameter, backwards compatible) and ConfigSchemaData exposes its schema directories. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mglaman
force-pushed
the
audit/5-result-cache
branch
from
August 5, 2026 19:33
94480e0 to
f526bdb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 9 of 9 in the legacy-code audit stack (on top of #1029). The highest-impact finding from the audit: PHPStan's result cache never invalidated when the analyzed Drupal site changed.
Why
PHPStan hashes its bootstrap files, but knows nothing about the Drupal extensions,
services.ymlfiles, and config schemas our bootstrap discovers. Enabling a module, editing aservices.yml, or upgrading core silently reused stale analysis results until the user ran--no-result-cacheor the cache expired.What changed
BootstrapResultCacheMetaExtensionimplements PHPStan'sResultCacheMetaExtension(phpstan.resultCacheMetaExtensiontag). Its hash covers:services.yml(path and content),*.schema.ymlfiles in the collected schema directories,\Drupal::VERSION, which catches tarball core upgrades (composer-managed upgrades are already covered by PHPStan's own composer.lock hashing).Any change invalidates the whole result cache. The hashing runs once per analysis over a few hundred small YAML files — well under 50ms. Discovered PHP files are deliberately not hashed; PHPStan hashes analyzed files itself.
To feed the extension,
ServiceMap::setDrupalServices()gains an optional second parameter recording the consumed yml paths (backwards compatible), andConfigSchemaDataexposes its schema directories.Testing
New unit tests assert the hash is deterministic, and changes when the extension list, a services.yml's content, or a schema directory changes. The tests run in separate processes because the underlying state is static. Full suite, self-analysis, and phpcs are green.
🤖 Generated with Claude Code