Repository navigation
Description
Bug report
Follow-up from a discussion with @staabm about why PHPStan re-analyses every file on CI for projects that do not commit composer.lock (Tempest, Laravel, and most libraries). The GitHub Actions result cache is restored correctly, but the very next run still re-analyses the whole project.
Root cause: when the result-cache metadata differs only in the Composer lock/installed files, ResultCacheManager asks PackageDependencyResolver::getChangedComposerPackages() which packages changed and re-seeds just the files depending on them (the package-granular path added in 2.2.3). But the caller treats "no packages changed" the same as "could not determine":
// src/Analyser/ResultCache/ResultCacheManager.php (2.2.5, around line 276)
if ($changedPackages === null || $changedPackages === []) {
// ... "metadata do not match" ...
return /* full re-analysis of every file */;
}null means "installed.php could not be parsed, fall back to full analysis to be safe". [] means the opposite: parsing succeeded and no installed package's version or reference changed. Both currently trigger a full re-analysis, so any change to composer.lock that is not reflected as a package-version change in vendor/composer/installed.php throws away the entire cache.
composerLocks in the meta is a full hash of composer.lock, while getChangedComposerPackages() compares per-package reference/version read from vendor/composer/installed.php. Plenty of things change the lock hash without changing any installed reference: a different Composer patch version regenerating the file, dist/time metadata, or a content-hash change from an unrelated composer.json edit.
Reproduction (deterministic, PHPStan 2.2.5)
# a project with at least one dependency, phpstan.neon with `level` + `tmpDir`, and some source files
vendor/bin/phpstan analyse # cold, builds the cache
vendor/bin/phpstan analyse -vvv # "Result cache restored. 0 files will be reanalysed."
# now change ONLY the lock, not installed.php:
# edit any "time": "..." value in composer.lock
# (the "time" field exists in composer.lock but not in vendor/composer/installed.php)
vendor/bin/phpstan analyse -vvv
# => "Result cache not used because the metadata do not match: composerLocks"
# and every file is re-analysed
vendor/composer/installed.php is byte-identical across the two runs, so getChangedComposerPackages() returns [], yet the run still goes full. I confirmed the return value is [] (not null) by calling the method directly with two metadata snapshots that share an identical composerInstalled.
Why it bites CI
Libraries and frameworks commonly gitignore composer.lock. Their CI installs with no committed lock, so every job regenerates it (e.g. Tempest's coding-conventions.yml uses ramsey/composer-install, and composer install with no lock resolves from scratch). Any run-to-run difference in the generated lock that is not a package-version change then forces a full re-analysis on top of a cache that was restored correctly (for example a different Composer version between runs, or a composer.json edit that resolves to the same package versions).
There is also a related, separate effect worth mentioning but not the same bug: with a floating phpstan/phpstan: ^2.0 and no committed lock, every new PHPStan release flips the phpstanVersion meta key and forces one full re-analysis on the next CI run. That one is defensible because a version bump can change any result. The composerLocks-only case above is not, because PHPStan's own package diff already established that nothing changed.
Expected output
When composer.lock changed but getChangedComposerPackages() reports that no installed package's version or reference changed (an empty result), PHPStan should keep the restored cache and re-analyse only genuinely changed source files, exactly as it does when nothing changed at all. Only the null case (installed.php unparseable, so the change set is unknown) should fall back to a full re-analysis.
I have a fix that distinguishes [] from null and will open a PR against 2.2.x with an end-to-end test.
Did PHPStan help you today?
Every day. The package-granular invalidation from 2.2.3 is already a big improvement for monorepos; this is just closing the last gap next to it.
Activity
mergeable commentedon Jul 22, 2026
This bug report is missing a link to reproduction at phpstan.org/try.
It will most likely be closed after manual review.
github-actions commentedon Aug 23, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.