Skip to content

Commit

Permalink
Add list of statements to BeforeFileAnalysisEvent
Browse files Browse the repository at this point in the history
Fixes: #10725
  • Loading branch information
ohader committed Feb 19, 2024
1 parent a97a121 commit 2943cfe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Analyzer/FileAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 17 additions & 1 deletion src/Psalm/Plugin/EventHandler/Event/BeforeFileAnalysisEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Psalm\Plugin\EventHandler\Event;

use PhpParser\Node\Stmt;
use Psalm\Codebase;
use Psalm\Context;
use Psalm\StatementsSource;
Expand All @@ -13,22 +14,29 @@ final class BeforeFileAnalysisEvent
private Context $file_context;
private FileStorage $file_storage;
private Codebase $codebase;
/**
* @var list<Stmt>
*/
private array $stmts;

/**
* Called before a file has been checked
*
* @param list<Stmt> $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
Expand All @@ -50,4 +58,12 @@ public function getCodebase(): Codebase
{
return $this->codebase;
}

/**
* @return list<Stmt>
*/
public function getStmts(): array
{
return $this->stmts;
}
}

0 comments on commit 2943cfe

Please sign in to comment.