Skip to content

Result cache not invalidated when a Composer package providing a PHPStan rule/extension is updated #14986

Closed
phpstan/phpstan-src
#6088

Description

@SanderMuller

Bug report

Follow-up to a discussion with @staabm on #6086. The package-granular result-cache invalidation from 2.2.3 (phpstan/phpstan-src#5933) does not invalidate the cache when a Composer package that registers a class in PHPStan's DI container (a rule or extension, e.g. larastan) is updated.

getChangedComposerPackages() correctly reports the changed package, and the incremental loop then re-seeds only the files that depend on it through code references. But an extension package is not referenced by the analysed code; its rules/extensions are loaded into the container and can affect the analysis of every file. So zero files get re-seeded, and the previous results are served from the cache even though a rule changed.

projectExtensionFiles (which would catch a changed extension file by hash) does not cover this either: getProjectExtensionFiles() skips service classes whose file lives under vendor/ and has no tracked dependencies, so a vendor-shipped rule is never tracked. I confirmed the saved cache's projectExtensionFiles is empty in this scenario.

This is a regression from #5933. Before it, any composerInstalled/composerLocks change forced a full re-analysis, which happened to catch this; on 2.2.3 through 2.2.5 it no longer does.

Reproduction

A small package that ships a PHPStan rule, registered via its own extension.neon:

final class MyRule implements Rule
{
    public function getNodeType(): string { return Node\Stmt\Class_::class; }
    public function processNode(Node $node, Scope $scope): array
    {
        return [RuleErrorBuilder::message('V1 flagged a class')->identifier('acme.myRule')->build()];
    }
}

The analysed project requires that package and includes its extension.neon, with a tmpDir set.

vendor/bin/phpstan analyse            # reports "V1 flagged a class" on each class
# now the package is updated (composer update) and its rule now returns 'V2 flagged a class'
vendor/bin/phpstan analyse -vvv
# => "Composer packages changed (acme/rules); re-analysing only the files depending on them."
#    "Result cache restored. 0 files will be reanalysed."
#    still reports "V1 flagged a class"   <- stale

I reproduced this on 2.2.x with the rule package installed via a Composer path repository, changing the rule body and bumping the package's reference in vendor/composer/installed.php (what composer update does). On 2.2.2 (pre-#5933) the same update triggered a full re-analysis and reported V2 correctly.

Expected output

Updating a Composer package that provides a class registered in PHPStan's DI container (a rule, extension, and so on) should invalidate the whole result cache, because that code can affect the analysis of every file. Packages that do not contribute anything to the container can stay on the file-granular path.

I have a fix and will open a PR against 2.2.x.

Did PHPStan help you today?

Yes, every day.

Activity

  1. mergeable commented on Jul 22, 2026

    @mergeable

    This bug report is missing a link to reproduction at phpstan.org/try.

    It will most likely be closed after manual review.

  2. staabm commented on Jul 23, 2026

    @staabm
    Contributor
  3. reopened this on Jul 23, 2026
  4. github-actions commented on Aug 27, 2026

    @github-actions

    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.

  5. locked as resolved and limited conversation to collaborators on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions