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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Psalm/Internal/Analyzer/FileAnalyzer.php
Expand Up @@ -150,8 +150,7 @@ 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);

if ($codebase->alter_code) {
Expand Down
18 changes: 17 additions & 1 deletion src/Psalm/Plugin/EventHandler/Event/BeforeFileAnalysisEvent.php
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;
}
}