From 1c2650fe6585d7b373f99b05c08c77f2127a4638 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 13 Dec 2020 07:17:13 +0100 Subject: [PATCH] preserve analyzers until the end of file (#4834) * preserve analyzers until the end of file * remove unused variable --- examples/TemplateChecker.php | 2 +- src/Psalm/Internal/Analyzer/FileAnalyzer.php | 9 +++------ .../Analyzer/Statements/Expression/IncludeAnalyzer.php | 1 - 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/examples/TemplateChecker.php b/examples/TemplateChecker.php index 79f5b7100..b6265de40 100644 --- a/examples/TemplateChecker.php +++ b/examples/TemplateChecker.php @@ -18,7 +18,7 @@ class TemplateAnalyzer extends Psalm\Internal\Analyzer\FileAnalyzer { const VIEW_CLASS = 'Your\\View\\Class'; - public function analyze(?Context $file_context = null, bool $preserve_analyzers = false, ?Context $global_context = null): void + public function analyze(?Context $file_context = null, ?Context $global_context = null): void { $codebase = $this->project_analyzer->getCodebase(); $stmts = $codebase->getStatementsForFile($this->file_path); diff --git a/src/Psalm/Internal/Analyzer/FileAnalyzer.php b/src/Psalm/Internal/Analyzer/FileAnalyzer.php index 6c20a2826..649014c87 100644 --- a/src/Psalm/Internal/Analyzer/FileAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FileAnalyzer.php @@ -123,7 +123,6 @@ class FileAnalyzer extends SourceAnalyzer public function analyze( ?Context $file_context = null, - bool $preserve_analyzers = false, ?Context $global_context = null ): void { $codebase = $this->project_analyzer->getCodebase(); @@ -211,11 +210,6 @@ class FileAnalyzer extends SourceAnalyzer $class_analyzer->analyze(null, $this->context); } - if (!$preserve_analyzers) { - $this->class_analyzers_to_analyze = []; - $this->interface_analyzers_to_analyze = []; - } - if ($codebase->config->check_for_throws_in_global_scope) { $uncaught_throws = $statements_analyzer->getUncaughtThrows($this->context); foreach ($uncaught_throws as $possibly_thrown_exception => $codelocations) { @@ -277,6 +271,9 @@ class FileAnalyzer extends SourceAnalyzer foreach ($codebase->config->after_file_checks as $plugin_class) { $plugin_class::afterAnalyzeFile($this, $this->context, $file_storage, $codebase); } + + $this->class_analyzers_to_analyze = []; + $this->interface_analyzers_to_analyze = []; } /** diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php index 795ee8c42..515e92383 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php @@ -178,7 +178,6 @@ class IncludeAnalyzer try { $include_file_analyzer->analyze( $context, - false, $global_context ); } catch (\Psalm\Exception\UnpreparedAnalysisException $e) {