1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Add better file location recognition for imports

This commit is contained in:
Matthew Brown 2016-08-24 18:13:22 -04:00
parent e5a6f0d42f
commit 1327b9e604
2 changed files with 6 additions and 2 deletions

View File

@ -22,7 +22,7 @@ abstract class ClassLikeChecker implements StatementsSource
{ {
protected static $SPECIAL_TYPES = ['int', 'string', 'float', 'bool', 'false', 'object', 'empty', 'callable', 'array']; protected static $SPECIAL_TYPES = ['int', 'string', 'float', 'bool', 'false', 'object', 'empty', 'callable', 'array'];
protected $file_name; public $file_name;
protected $class; protected $class;
protected $namespace; protected $namespace;
protected $aliased_classes; protected $aliased_classes;

View File

@ -244,7 +244,8 @@ class StatementsChecker
} }
} elseif ($stmt instanceof PhpParser\Node\Stmt\Class_) { } elseif ($stmt instanceof PhpParser\Node\Stmt\Class_) {
(new ClassChecker($stmt, $this->source, $stmt->name))->check(); $class_checker = new ClassChecker($stmt, $this->source, $stmt->name);
$class_checker->file_name = $context->file_name ?: $this->file_name;
} elseif ($stmt instanceof PhpParser\Node\Stmt\Nop) { } elseif ($stmt instanceof PhpParser\Node\Stmt\Nop) {
// do nothing // do nothing
@ -3472,7 +3473,10 @@ class StatementsChecker
if (file_exists($path_to_file)) { if (file_exists($path_to_file)) {
$include_stmts = FileChecker::getStatementsForFile($path_to_file); $include_stmts = FileChecker::getStatementsForFile($path_to_file);
$old_file_name = $context->file_name;
$context->file_name = $this->file_name = Config::getInstance()->shortenFileName($path_to_file);
$this->check($include_stmts, $context); $this->check($include_stmts, $context);
$context->file_name = $this->file_name = $old_file_name;
return; return;
} }
} }