Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7535 from ohader/issue-7534
- Loading branch information
Showing
5 changed files
with
185 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Psalm/Plugin/EventHandler/BeforeStatementAnalysisInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\Plugin\EventHandler; | ||
|
||
use Psalm\Plugin\EventHandler\Event\BeforeStatementAnalysisEvent; | ||
|
||
interface BeforeStatementAnalysisInterface | ||
{ | ||
/** | ||
* Called before a statement has been checked | ||
* | ||
* @return null|false Whether to continue | ||
* + `null` continues with next event handler | ||
* + `false` stops analyzing current statement in StatementsAnalyzer | ||
*/ | ||
public static function beforeStatementAnalysis(BeforeStatementAnalysisEvent $event): ?bool; | ||
} |
84 changes: 84 additions & 0 deletions
84
src/Psalm/Plugin/EventHandler/Event/BeforeStatementAnalysisEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\Plugin\EventHandler\Event; | ||
|
||
use PhpParser\Node\Stmt; | ||
use Psalm\Codebase; | ||
use Psalm\Context; | ||
use Psalm\FileManipulation; | ||
use Psalm\StatementsSource; | ||
|
||
final class BeforeStatementAnalysisEvent | ||
{ | ||
private Stmt $stmt; | ||
private Context $context; | ||
private StatementsSource $statements_source; | ||
private Codebase $codebase; | ||
/** | ||
* @var list<FileManipulation> | ||
*/ | ||
private array $file_replacements; | ||
|
||
/** | ||
* Called after a statement has been checked | ||
* | ||
* @param list<FileManipulation> $file_replacements | ||
* @internal | ||
*/ | ||
public function __construct( | ||
Stmt $stmt, | ||
Context $context, | ||
StatementsSource $statements_source, | ||
Codebase $codebase, | ||
array $file_replacements = [] | ||
) { | ||
$this->stmt = $stmt; | ||
$this->context = $context; | ||
$this->statements_source = $statements_source; | ||
$this->codebase = $codebase; | ||
$this->file_replacements = $file_replacements; | ||
} | ||
|
||
public function getStmt(): Stmt | ||
{ | ||
return $this->stmt; | ||
} | ||
|
||
public function setStmt(Stmt $stmt): void | ||
{ | ||
$this->stmt = $stmt; | ||
} | ||
|
||
public function getContext(): Context | ||
{ | ||
return $this->context; | ||
} | ||
|
||
public function getStatementsSource(): StatementsSource | ||
{ | ||
return $this->statements_source; | ||
} | ||
|
||
public function getCodebase(): Codebase | ||
{ | ||
return $this->codebase; | ||
} | ||
|
||
/** | ||
* @return list<FileManipulation> | ||
*/ | ||
public function getFileReplacements(): array | ||
{ | ||
return $this->file_replacements; | ||
} | ||
|
||
/** | ||
* @param list<FileManipulation> $file_replacements | ||
*/ | ||
public function setFileReplacements(array $file_replacements): void | ||
{ | ||
$this->file_replacements = $file_replacements; | ||
} | ||
} |