Skip to content

Commit

Permalink
Merge pull request #9012 from kkmuffme/ignore-missingfile-error-for-f…
Browse files Browse the repository at this point in the history
…ile_exists-files

dont report MissingFile error when file_exists is validated beforehand
  • Loading branch information
orklah committed Jan 9, 2023
2 parents f415ad5 + 166df8a commit 9366c5e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -178,6 +179,22 @@ public static function handle(

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;
Expand Down
Expand Up @@ -231,6 +231,15 @@ public static function analyze(
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(
Expand Down

0 comments on commit 9366c5e

Please sign in to comment.