1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #205 - add file references at analysis stage too

This commit is contained in:
Matthew Brown 2017-08-22 12:38:38 -04:00
parent fb656f3575
commit 622217b708
5 changed files with 35 additions and 6 deletions

View File

@ -19,6 +19,7 @@ use Psalm\Issue\UndefinedTrait;
use Psalm\Issue\UnimplementedAbstractMethod;
use Psalm\Issue\UnimplementedInterfaceMethod;
use Psalm\IssueBuffer;
use Psalm\Provider\FileReferenceProvider;
use Psalm\StatementsSource;
use Psalm\Storage\ClassLikeStorage;
use Psalm\Storage\PropertyStorage;
@ -990,6 +991,11 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
}
}
FileReferenceProvider::addFileReferenceToClass(
$code_location->file_path,
strtolower($fq_class_name)
);
return true;
}

View File

@ -662,7 +662,7 @@ class FunctionChecker extends FunctionLikeChecker
if (strpos($mapping_function_id, '::') !== false) {
list($callable_fq_class_name) = explode('::', $mapping_function_id);
if (in_array($callable_fq_class_name, ['self', 'static', 'parent'])) {
if (in_array($callable_fq_class_name, ['self', 'static', 'parent'], true)) {
$mapping_return_type = Type::getMixed();
continue;
}

View File

@ -903,7 +903,10 @@ class ProjectChecker
$analysis_worker,
/** @return array */
function () {
return IssueBuffer::getIssuesData();
return [
'issues' => IssueBuffer::getIssuesData(),
'file_references' => FileReferenceProvider::getAllFileReferences(),
];
}
);
@ -913,10 +916,11 @@ class ProjectChecker
* file_name: string, file_path: string, snippet: string, from: int, to: int, snippet_from: int,
* snippet_to: int, column: int}>>
*/
$forked_issues_data = $pool->wait();
$forked_pool_data = $pool->wait();
foreach ($forked_issues_data as $issues_data) {
IssueBuffer::addIssues($issues_data);
foreach ($forked_pool_data as $pool_data) {
IssueBuffer::addIssues($pool_data['issues']);
FileReferenceProvider::addFileReferences($pool_data['file_references']);
}
$did_fork_pool_have_error = $pool->didHaveError();

View File

@ -2168,7 +2168,7 @@ class CallChecker
if (strpos($function_id, '::') !== false) {
list($callable_fq_class_name) = explode('::', $function_id);
if (!in_array($callable_fq_class_name, ['self', 'static', 'parent'])) {
if (!in_array($callable_fq_class_name, ['self', 'static', 'parent'], true)) {
if (ClassLikeChecker::checkFullyQualifiedClassLikeName(
$project_checker,
$callable_fq_class_name,

View File

@ -80,6 +80,25 @@ class FileReferenceProvider
self::$file_references_to_class[$fq_class_name_lc][$source_file] = true;
}
/**
* @return array<string, array<string,bool>>
*/
public static function getAllFileReferences()
{
return self::$file_references_to_class;
}
/**
* @param array<string, array<string,bool>> $references
* @psalm-suppress InvalidPropertyAssignment
*
* @return void
*/
public static function addFileReferences(array $references)
{
self::$file_references_to_class = array_merge_recursive($references, self::$file_references_to_class);
}
/**
* @param string $source_file
* @param string $fq_class_name_lc