1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Merge pull request #9012 from kkmuffme/ignore-missingfile-error-for-file_exists-files

dont report MissingFile error when file_exists is validated beforehand
This commit is contained in:
orklah 2023-01-09 23:33:04 +01:00 committed by GitHub
commit 9366c5ed32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -10,6 +10,7 @@ use Psalm\Internal\Analyzer\FunctionLikeAnalyzer;
use Psalm\Internal\Analyzer\Statements\Expression\AssertionFinder;
use Psalm\Internal\Analyzer\Statements\Expression\ExpressionIdentifier;
use Psalm\Internal\Analyzer\Statements\Expression\Fetch\ConstFetchAnalyzer;
use Psalm\Internal\Analyzer\Statements\Expression\IncludeAnalyzer;
use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\Internal\Codebase\VariableUseGraph;
@ -178,6 +179,22 @@ class NamedFunctionCallHandler
if ($var_id) {
$context->phantom_files[$var_id] = true;
return;
}
// literal string or (magic) const in file path
$codebase = $statements_analyzer->getCodebase();
$config = $codebase->config;
$path_to_file = IncludeAnalyzer::getPathTo(
$first_arg->value,
$statements_analyzer->node_data,
$statements_analyzer,
$statements_analyzer->getFileName(),
$config,
);
if ($path_to_file) {
$context->phantom_files[$path_to_file] = true;
}
return;

View File

@ -231,6 +231,15 @@ class IncludeAnalyzer
return true;
}
if (isset($context->phantom_files[$path_to_file])) {
return true;
}
$var_id = ExpressionIdentifier::getExtendedVarId($stmt->expr, null);
if ($var_id && isset($context->phantom_files[$var_id])) {
return true;
}
$source = $statements_analyzer->getSource();
IssueBuffer::maybeAdd(