Skip to content

Use external file dependencies instead of ResultCacheMetaExtension#478

Draft
janedbal wants to merge 1 commit intophpstan:2.0.xfrom
janedbal:external-file-dependencies
Draft

Use external file dependencies instead of ResultCacheMetaExtension#478
janedbal wants to merge 1 commit intophpstan:2.0.xfrom
janedbal:external-file-dependencies

Conversation

@janedbal
Copy link
Copy Markdown
Contributor

Summary

  • Replace SymfonyContainerResultCacheMetaExtension (which caused full cache invalidation on any container change) with PHPStan's new external file dependency tracking
  • When the container XML changes, only files that actually call Container::get(), Container::has(), getParameter(), or hasParameter() are re-analyzed instead of the entire project

Motivation

The current SymfonyContainerResultCacheMetaExtension hashes the entire DI container state. Any change to any service definition invalidates the entire PHPStan result cache. On large Symfony projects with frequent service changes, this causes constant full re-analyses.

With this change, only the files that actually use the container (typically a few dozen controller/service files) are re-analyzed when the container XML changes — not the entire codebase.

See: #455
Depends on: phpstan/phpstan-src#5364

Changes

  • ServiceDynamicReturnTypeExtension: registers container XML as external dependency when Container::get()/has() is called
  • ParameterDynamicReturnTypeExtension: same for getParameter()/hasParameter()
  • ContainerInterfacePrivateServiceRule / ContainerInterfaceUnknownServiceRule: same for rule checks
  • extension.neon: passes containerXmlPath to extensions, removes SymfonyContainerResultCacheMetaExtension
  • rules.neon: moves container rules to services with explicit containerXmlPath argument

All new parameters are nullable with defaults for backward compatibility with older PHPStan versions.

Test plan

  • All 347 existing tests pass
  • Integration test with actual cache invalidation scenario

Co-Authored-By: Claude Code

Replace SymfonyContainerResultCacheMetaExtension (which caused full cache
invalidation on any container change) with PHPStan's new external file
dependency tracking. Now when the container XML changes, only files that
actually call Container::get(), Container::has(), getParameter(), or
hasParameter() are re-analyzed instead of the entire project.

All extensions and rules that read from ServiceMap or ParameterMap now
register the container XML path as an external file dependency via
ExternalFileDependencyRegistrar. The new parameters are optional (nullable)
for backward compatibility with older PHPStan versions.

Co-Authored-By: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant