1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 10:38:49 +01:00

Merge pull request #10728 from ohader/10725-before-file-analysis-event-stmts

This commit is contained in:
Bruce Weirdan 2024-02-19 19:37:42 -04:00 committed by GitHub
commit 6129891cc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -150,8 +150,7 @@ class FileAnalyzer extends SourceAnalyzer
return; 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); $codebase->config->eventDispatcher->dispatchBeforeFileAnalysis($event);
if ($codebase->alter_code) { if ($codebase->alter_code) {

View File

@ -2,6 +2,7 @@
namespace Psalm\Plugin\EventHandler\Event; namespace Psalm\Plugin\EventHandler\Event;
use PhpParser\Node\Stmt;
use Psalm\Codebase; use Psalm\Codebase;
use Psalm\Context; use Psalm\Context;
use Psalm\StatementsSource; use Psalm\StatementsSource;
@ -13,22 +14,29 @@ final class BeforeFileAnalysisEvent
private Context $file_context; private Context $file_context;
private FileStorage $file_storage; private FileStorage $file_storage;
private Codebase $codebase; private Codebase $codebase;
/**
* @var list<Stmt>
*/
private array $stmts;
/** /**
* Called before a file has been checked * Called before a file has been checked
* *
* @param list<Stmt> $stmts
* @internal * @internal
*/ */
public function __construct( public function __construct(
StatementsSource $statements_source, StatementsSource $statements_source,
Context $file_context, Context $file_context,
FileStorage $file_storage, FileStorage $file_storage,
Codebase $codebase Codebase $codebase,
array $stmts
) { ) {
$this->statements_source = $statements_source; $this->statements_source = $statements_source;
$this->file_context = $file_context; $this->file_context = $file_context;
$this->file_storage = $file_storage; $this->file_storage = $file_storage;
$this->codebase = $codebase; $this->codebase = $codebase;
$this->stmts = $stmts;
} }
public function getStatementsSource(): StatementsSource public function getStatementsSource(): StatementsSource
@ -50,4 +58,12 @@ final class BeforeFileAnalysisEvent
{ {
return $this->codebase; return $this->codebase;
} }
/**
* @return list<Stmt>
*/
public function getStmts(): array
{
return $this->stmts;
}
} }