1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Add BeforeAnalyzeFileInterface (#2034)

This is a prerequisite of the plugin I mentioned in #378

This may be useful for other types of plugins
(e.g. checking raw file contents or file names)
This commit is contained in:
Tyson Andre 2019-08-18 10:40:07 -04:00 committed by Matthew Brown
parent 62dff200d5
commit ce03be2dc0
3 changed files with 23 additions and 0 deletions

View File

@ -422,6 +422,12 @@ class Config
*/
public $after_analysis = [];
/**
* Static methods to be called after codebase has been populated
* @var class-string<Hook\BeforeAnalyzeFileInterface>[]
*/
public $before_analyze_file = [];
/** @var array<string, mixed> */
private $predefined_constants;

View File

@ -163,6 +163,9 @@ class FileAnalyzer extends SourceAnalyzer implements StatementsSource
} catch (PhpParser\Error $e) {
return;
}
foreach ($codebase->config->before_analyze_file as $plugin_class) {
$plugin_class::beforeAnalyzeFile($this);
}
if ($codebase->alter_code) {
foreach ($stmts as $stmt) {

View File

@ -0,0 +1,14 @@
<?php
namespace Psalm\Plugin\Hook;
use Psalm\Internal\Analyzer\FileAnalyzer;
interface BeforeAnalyzeFileInterface
{
/**
* @return void
*/
public static function beforeAnalyzeFile(
FileAnalyzer $file_analyzer
);
}