Skip to content
Permalink
Browse files

Allow users to pass file names to Function::getStorage

  • Loading branch information...
muglug committed Jul 1, 2019
1 parent f5809ec commit e876feb0ea04087582dd27d0f6d9b2b3921135e5
Showing with 26 additions and 23 deletions.
  1. +26 −23 src/Psalm/Internal/Codebase/Functions.php
@@ -58,14 +58,12 @@ public function __construct(FileStorageProvider $storage_provider, Reflection $r
self::$stubbed_functions = [];
}
/**
* @param StatementsAnalyzer|null $statements_analyzer
* @param string $function_id
*
* @return FunctionLikeStorage
*/
public function getStorage($statements_analyzer, $function_id)
{
public function getStorage(
?StatementsAnalyzer $statements_analyzer,
string $function_id,
?string $root_file_path = null,
?string $checked_file_path = null
) : FunctionLikeStorage {
if (isset(self::$stubbed_functions[strtolower($function_id)])) {
return self::$stubbed_functions[strtolower($function_id)];
}
@@ -74,31 +72,36 @@ public function getStorage($statements_analyzer, $function_id)
return $this->reflection->getFunctionStorage($function_id);
}
if (!$statements_analyzer) {
throw new \UnexpectedValueException('$statements_analyzer must not be null here');
if ($statements_analyzer) {
$root_file_path = $statements_analyzer->getRootFilePath();
$checked_file_path = $statements_analyzer->getFilePath();
} elseif (!$root_file_path || !$checked_file_path) {
throw new \UnexpectedValueException(
'Expecting non-empty $root_file_path and $checked_file_path'
);
}
$file_path = $statements_analyzer->getRootFilePath();
$checked_file_path = $statements_analyzer->getFilePath();
$file_storage = $this->file_storage_provider->get($file_path);
$file_storage = $this->file_storage_provider->get($root_file_path);
$function_analyzers = $statements_analyzer->getFunctionAnalyzers();
if ($statements_analyzer) {
$function_analyzers = $statements_analyzer->getFunctionAnalyzers();
if (isset($function_analyzers[$function_id])) {
$function_id = $function_analyzers[$function_id]->getMethodId();
if (isset($function_analyzers[$function_id])) {
$function_id = $function_analyzers[$function_id]->getMethodId();
if (isset($file_storage->functions[$function_id])) {
return $file_storage->functions[$function_id];
}
}
// closures can be returned here
if (isset($file_storage->functions[$function_id])) {
return $file_storage->functions[$function_id];
}
}
// closures can be returned here
if (isset($file_storage->functions[$function_id])) {
return $file_storage->functions[$function_id];
}
if (!isset($file_storage->declaring_function_ids[$function_id])) {
if ($checked_file_path !== $file_path) {
if ($checked_file_path !== $root_file_path) {
$file_storage = $this->file_storage_provider->get($checked_file_path);
if (isset($file_storage->functions[$function_id])) {
@@ -107,7 +110,7 @@ public function getStorage($statements_analyzer, $function_id)
}
throw new \UnexpectedValueException(
'Expecting ' . $function_id . ' to have storage in ' . $file_path
'Expecting ' . $function_id . ' to have storage in ' . $checked_file_path
);
}

0 comments on commit e876feb

Please sign in to comment.
You can’t perform that action at this time.