Repository navigation
Don't report includes that need the container at the top level - #1066
Merged
Merged
Conversation
loadInclude() and module_load_include() run require_once during analysis. When the file's top-level code calls \Drupal::something(), it throws ContainerNotInitializedException, which was reported as an unloadable file. PHP won't re-run the file, so only the first call in each process failed. That's why core saw these errors at random. Treat the exception as loaded, matching DrupalAutoloader::loadAndCatchErrors(). Fixes #1062 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #1062.
LoadIncludesandModuleLoadIncluderunrequire_onceon the include during analysis. If the file's top-level code uses the container, it throwsContainerNotInitializedException, and the rules reportA file could not be loaded.Core hits this with
entity_test.install:The file exists and its functions are defined, so the error is a false positive. It also looks random.
require_oncemarks the file as included even when it throws, so only the first call in each process fails. I expect that's why the failures move around between core's runs: the first call depends on how files are split across PHPStan workers.Catch the exception and treat the include as loaded.
DrupalAutoloader::loadAndCatchErrors()already handles this exception, and its.installloading skipsentity_testoutright. Other exceptions still report an error.This keeps
require_onceinstead of only checking that the file exists, because analysis needs the functions the include declares.entity_test_install()is called right afterloadInclude()in core's tests.Testing
\Drupal::moduleHandler()at the top level. Both failed before the fix.loadInclude('entity_test', 'install')calls against the real core file in one process. Before the fix, only the first reports an error. After the fix, neither does.Lint is red until #1064 and #1065 land. Neither error comes from this change.
🤖 Generated with Claude Code