mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Only warn about issues in files that we’re trying to scan
This commit is contained in:
parent
7800d34b59
commit
a89018d9ae
@ -611,7 +611,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
|
||||
|
||||
$config = Config::getInstance();
|
||||
|
||||
if (!$config->excludeIssueInFile('PropertyNotSetInConstructor', $this->getFilePath())) {
|
||||
if ($config->reportIssueInFile('PropertyNotSetInConstructor', $this->getFilePath())) {
|
||||
$uninitialized_variables = [];
|
||||
$uninitialized_properties = [];
|
||||
|
||||
@ -727,7 +727,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
|
||||
$global_context ? clone $global_context : null
|
||||
);
|
||||
|
||||
if (!$config->excludeIssueInFile('InvalidReturnType', $source->getFilePath())) {
|
||||
if ($config->reportIssueInFile('InvalidReturnType', $source->getFilePath())) {
|
||||
$return_type_location = null;
|
||||
$secondary_return_type_location = null;
|
||||
|
||||
|
@ -265,7 +265,7 @@ class FileChecker extends SourceChecker implements StatementsSource
|
||||
$function_context->collect_references = $this->project_checker->collect_references;
|
||||
$function_checker->analyze($function_context, $this->context);
|
||||
|
||||
if (!$config->excludeIssueInFile('InvalidReturnType', $this->file_path)) {
|
||||
if ($config->reportIssueInFile('InvalidReturnType', $this->file_path)) {
|
||||
/** @var string */
|
||||
$method_id = $function_checker->getMethodId();
|
||||
|
||||
@ -384,7 +384,7 @@ class FileChecker extends SourceChecker implements StatementsSource
|
||||
*/
|
||||
public function visitAndAnalyzeMethods(Context $file_context = null, $update_docblocks = false)
|
||||
{
|
||||
$this->project_checker->registerVisitedFile($this->file_path);
|
||||
$this->project_checker->registerAnalyzableFile($this->file_path);
|
||||
$this->visit($file_context);
|
||||
$this->analyze($update_docblocks);
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ class ProjectChecker
|
||||
private $files_to_visit = [];
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private $files_to_analyze = [];
|
||||
|
||||
@ -557,7 +557,7 @@ class ProjectChecker
|
||||
$file_path = (string)$iterator->getRealPath();
|
||||
|
||||
if ($allow_non_project_files || $config->isInProjectDirs($file_path)) {
|
||||
$this->files_to_analyze[$file_path] = $file_path;
|
||||
$this->files_to_analyze[$file_path] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -651,33 +651,35 @@ class ProjectChecker
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->files_to_analyze[$file_path] = $file_path;
|
||||
$this->files_to_analyze[$file_path] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file_name
|
||||
* @param string $file_path
|
||||
* @return void
|
||||
*/
|
||||
public function checkFile($file_name)
|
||||
public function checkFile($file_path)
|
||||
{
|
||||
if ($this->debug_output) {
|
||||
echo 'Checking ' . $file_name . PHP_EOL;
|
||||
echo 'Checking ' . $file_path . PHP_EOL;
|
||||
}
|
||||
|
||||
if (!$this->config) {
|
||||
$this->config = $this->getConfigForPath($file_name);
|
||||
$this->config = $this->getConfigForPath($file_path);
|
||||
}
|
||||
|
||||
$start_checks = (int)microtime(true);
|
||||
|
||||
$this->config->hide_external_errors = $this->config->isInProjectDirs($file_name);
|
||||
$this->config->hide_external_errors = $this->config->isInProjectDirs($file_path);
|
||||
|
||||
$this->files_to_analyze[$file_path] = true;
|
||||
|
||||
$filetype_handlers = $this->config->getFiletypeHandlers();
|
||||
|
||||
FileReferenceProvider::loadReferenceCache();
|
||||
|
||||
$file_checker = $this->visitFile($file_name, $filetype_handlers, true);
|
||||
$file_checker = $this->visitFile($file_path, $filetype_handlers, true);
|
||||
|
||||
if ($this->debug_output) {
|
||||
echo 'Analyzing ' . $file_checker->getFilePath() . PHP_EOL;
|
||||
@ -1066,9 +1068,10 @@ class ProjectChecker
|
||||
* @param string $file_path
|
||||
* @return void
|
||||
*/
|
||||
public function registerVisitedFile($file_path)
|
||||
public function registerAnalyzableFile($file_path)
|
||||
{
|
||||
$this->visited_files[$file_path] = true;
|
||||
$this->files_to_analyze[$file_path] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1215,4 +1218,13 @@ class ProjectChecker
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file_path
|
||||
* @return bool
|
||||
*/
|
||||
public function canReportIssues($file_path)
|
||||
{
|
||||
return isset($this->files_to_analyze[$file_path]);
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ class StatementsChecker extends SourceChecker implements StatementsSource
|
||||
|
||||
$config = Config::getInstance();
|
||||
|
||||
if (!$config->excludeIssueInFile('InvalidReturnType', $this->getFilePath())) {
|
||||
if ($config->reportIssueInFile('InvalidReturnType', $this->getFilePath())) {
|
||||
/** @var string */
|
||||
$method_id = $function_checkers[$stmt->name]->getMethodId();
|
||||
|
||||
|
@ -498,23 +498,25 @@ class Config
|
||||
* @param string $file_path
|
||||
* @return bool
|
||||
*/
|
||||
public function excludeIssueInFile($issue_type, $file_path)
|
||||
public function reportIssueInFile($issue_type, $file_path)
|
||||
{
|
||||
if (!$this->totally_typed && in_array($issue_type, self::$MIXED_ISSUES)) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->project_files && $this->hide_external_errors) {
|
||||
if (!$this->isInProjectDirs($file_path)) {
|
||||
return true;
|
||||
if ($this->hide_external_errors) {
|
||||
$project_checker = ProjectChecker::getInstance();
|
||||
|
||||
if (!$project_checker->canReportIssues($file_path)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getReportingLevelForFile($issue_type, $file_path) === self::REPORT_SUPPRESS) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ class IssueBuffer
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($config->excludeIssueInFile($issue_type, $e->getFilePath())) {
|
||||
if (!$config->reportIssueInFile($issue_type, $e->getFilePath())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -125,8 +125,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
||||
</psalm>'
|
||||
);
|
||||
|
||||
$this->assertTrue($config->excludeIssueInFile('MissingReturnType', realpath('tests/ConfigTest.php')));
|
||||
$this->assertTrue($config->excludeIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php')));
|
||||
$this->assertFalse($config->reportIssueInFile('MissingReturnType', realpath('tests/ConfigTest.php')));
|
||||
$this->assertFalse($config->reportIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php')));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,10 +156,6 @@ class ConfigTest extends PHPUnit_Framework_TestCase
|
||||
</psalm>'
|
||||
);
|
||||
|
||||
$this->assertTrue($config->excludeIssueInFile('MissingReturnType', realpath('tests/ConfigTest.php')));
|
||||
$this->assertFalse($config->excludeIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php')));
|
||||
$this->assertFalse($config->excludeIssueInFile('MissingReturnType', realpath('src/Psalm/Checker/FileChecker.php')));
|
||||
|
||||
$this->assertSame('info', $config->getReportingLevelForFile('MissingReturnType', realpath('src/Psalm/Type.php')));
|
||||
$this->assertSame('error', $config->getReportingLevelForFile('MissingReturnType', realpath('src/Psalm/Checker/FileChecker.php')));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user