mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Scan compoer autoload files before any sweep of code
This commit is contained in:
parent
72a2a80619
commit
5afe3b10fa
@ -219,7 +219,13 @@ class FunctionChecker extends FunctionLikeChecker
|
||||
|
||||
if ($docblock_info->return_type) {
|
||||
if (!$storage->return_type) {
|
||||
$storage->return_type = Type::parseString($docblock_info->return_type);
|
||||
$namespace = $reflection_function->getNamespaceName();
|
||||
$aliases = new \Psalm\Aliases($namespace);
|
||||
$fq_return_type = FunctionLikeChecker::fixUpLocalType(
|
||||
$docblock_info->return_type,
|
||||
$aliases
|
||||
);
|
||||
$storage->return_type = Type::parseString($fq_return_type);
|
||||
$storage->return_type->setFromDocblock();
|
||||
|
||||
if ($docblock_info->ignore_nullable_return) {
|
||||
|
@ -1701,6 +1701,7 @@ class ProjectChecker
|
||||
$this->cache_provider->use_igbinary = $config->use_igbinary;
|
||||
|
||||
$config->visitStubFiles($this);
|
||||
$config->visitComposerAutoloadFiles($this);
|
||||
$config->initializePlugins($this);
|
||||
|
||||
return $config;
|
||||
@ -1718,6 +1719,7 @@ class ProjectChecker
|
||||
$this->cache_provider->use_igbinary = $config->use_igbinary;
|
||||
|
||||
$config->visitStubFiles($this);
|
||||
$config->visitComposerAutoloadFiles($this);
|
||||
$config->initializePlugins($this);
|
||||
}
|
||||
|
||||
@ -1738,6 +1740,7 @@ class ProjectChecker
|
||||
$this->config = Config::loadFromXMLFile($path_to_config, $base_dir);
|
||||
|
||||
$this->config->visitStubFiles($this);
|
||||
$this->config->visitComposerAutoloadFiles($this);
|
||||
$this->config->initializePlugins($this);
|
||||
}
|
||||
|
||||
|
@ -714,6 +714,49 @@ class Config
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*
|
||||
* @psalm-suppress MixedAssignment
|
||||
* @psalm-suppress MixedArrayAccess
|
||||
*/
|
||||
public function visitComposerAutoloadFiles(ProjectChecker $project_checker)
|
||||
{
|
||||
$project_checker->register_global_functions = true;
|
||||
|
||||
$composer_json_path = $this->base_dir . 'composer.json'; // this should ideally not be hardcoded
|
||||
|
||||
if (!file_exists($composer_json_path)) {
|
||||
$project_checker->register_global_functions = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyFalseArgument */
|
||||
if (!$composer_json = json_decode(file_get_contents($composer_json_path), true)) {
|
||||
throw new \UnexpectedValueException('Invalid composer.json at ' . $composer_json_path);
|
||||
}
|
||||
|
||||
if (isset($composer_json['autoload']['files'])) {
|
||||
/** @var string[] */
|
||||
$files = $composer_json['autoload']['files'];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$file_path = realpath($this->base_dir . $file);
|
||||
|
||||
if (!$file_path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$file_checker = new FileChecker($file_path, $project_checker);
|
||||
$project_checker->file_storage_provider->create($file_path);
|
||||
$file_checker->scan();
|
||||
}
|
||||
}
|
||||
|
||||
$project_checker->register_global_functions = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user