diff --git a/src/Psalm/Internal/Analyzer/FileAnalyzer.php b/src/Psalm/Internal/Analyzer/FileAnalyzer.php index 80db22ed9d1..b69f01481d2 100644 --- a/src/Psalm/Internal/Analyzer/FileAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FileAnalyzer.php @@ -150,9 +150,9 @@ public function analyze( return; } - $event = new BeforeFileAnalysisEvent($this, $this->context, $file_storage, $codebase); - + $event = new BeforeFileAnalysisEvent($this, $this->context, $file_storage, $codebase, $stmts); $codebase->config->eventDispatcher->dispatchBeforeFileAnalysis($event); + $stmts = $event->getStmts(); if ($codebase->alter_code) { foreach ($stmts as $stmt) { diff --git a/src/Psalm/Plugin/EventHandler/Event/BeforeFileAnalysisEvent.php b/src/Psalm/Plugin/EventHandler/Event/BeforeFileAnalysisEvent.php index 249ab125b38..e04305afea3 100644 --- a/src/Psalm/Plugin/EventHandler/Event/BeforeFileAnalysisEvent.php +++ b/src/Psalm/Plugin/EventHandler/Event/BeforeFileAnalysisEvent.php @@ -2,6 +2,7 @@ namespace Psalm\Plugin\EventHandler\Event; +use PhpParser\Node\Stmt; use Psalm\Codebase; use Psalm\Context; use Psalm\StatementsSource; @@ -13,22 +14,29 @@ final class BeforeFileAnalysisEvent private Context $file_context; private FileStorage $file_storage; private Codebase $codebase; + /** + * @var list + */ + private array $stmts; /** * Called before a file has been checked * + * @param list $stmts * @internal */ public function __construct( StatementsSource $statements_source, Context $file_context, FileStorage $file_storage, - Codebase $codebase + Codebase $codebase, + array $stmts ) { $this->statements_source = $statements_source; $this->file_context = $file_context; $this->file_storage = $file_storage; $this->codebase = $codebase; + $this->stmts = $stmts; } public function getStatementsSource(): StatementsSource @@ -50,4 +58,12 @@ public function getCodebase(): Codebase { return $this->codebase; } + + /** + * @return list + */ + public function getStmts(): array + { + return $this->stmts; + } }