Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list of statements to BeforeFileAnalysisEvent #10728

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
ohader marked this conversation as resolved.
Show resolved Hide resolved

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;
}
}
Loading