From 1327b9e6049cf602f3569fe82a50519ab1cd2e85 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Wed, 24 Aug 2016 18:13:22 -0400 Subject: [PATCH] Add better file location recognition for imports --- src/Psalm/Checker/ClassLikeChecker.php | 2 +- src/Psalm/Checker/StatementsChecker.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Checker/ClassLikeChecker.php b/src/Psalm/Checker/ClassLikeChecker.php index 17ff3910a..b74ef0ce9 100644 --- a/src/Psalm/Checker/ClassLikeChecker.php +++ b/src/Psalm/Checker/ClassLikeChecker.php @@ -22,7 +22,7 @@ abstract class ClassLikeChecker implements StatementsSource { protected static $SPECIAL_TYPES = ['int', 'string', 'float', 'bool', 'false', 'object', 'empty', 'callable', 'array']; - protected $file_name; + public $file_name; protected $class; protected $namespace; protected $aliased_classes; diff --git a/src/Psalm/Checker/StatementsChecker.php b/src/Psalm/Checker/StatementsChecker.php index f62caaf4d..ab30fb5d6 100644 --- a/src/Psalm/Checker/StatementsChecker.php +++ b/src/Psalm/Checker/StatementsChecker.php @@ -244,7 +244,8 @@ class StatementsChecker } } 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) { // do nothing @@ -3472,7 +3473,10 @@ class StatementsChecker if (file_exists($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); + $context->file_name = $this->file_name = $old_file_name; return; } }