Skip to content

Commit

Permalink
Merge pull request #8503 from kkmuffme/fix-phpdoc-errors-reported-for…
Browse files Browse the repository at this point in the history
…-stubs-instead-of-files

use cache for declared function when available before falling back to stubs
  • Loading branch information
orklah committed Sep 22, 2022
2 parents 5bf59e4 + e803af4 commit ebabd4b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Psalm/Internal/Codebase/Functions.php
Expand Up @@ -84,8 +84,9 @@ public function getStorage(
$function_id = substr($function_id, 1);
}

$from_stubs = false;
if (isset(self::$stubbed_functions[$function_id])) {
return self::$stubbed_functions[$function_id];
$from_stubs = self::$stubbed_functions[$function_id];
}

$file_storage = null;
Expand Down Expand Up @@ -117,6 +118,10 @@ public function getStorage(
return $this->reflection->getFunctionStorage($function_id);
}

if ($from_stubs) {
return $from_stubs;
}

throw new UnexpectedValueException(
'Expecting non-empty $root_file_path and $checked_file_path'
);
Expand All @@ -135,6 +140,10 @@ public function getStorage(
}
}

if ($from_stubs) {
return $from_stubs;
}

throw new UnexpectedValueException(
'Expecting ' . $function_id . ' to have storage in ' . $checked_file_path
);
Expand All @@ -145,6 +154,10 @@ public function getStorage(
$declaring_file_storage = $this->file_storage_provider->get($declaring_file_path);

if (!isset($declaring_file_storage->functions[$function_id])) {
if ($from_stubs) {
return $from_stubs;
}

throw new UnexpectedValueException(
'Not expecting ' . $function_id . ' to not have storage in ' . $declaring_file_path
);
Expand Down

0 comments on commit ebabd4b

Please sign in to comment.