1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Wait to evaluate property defaults until analysis

This commit is contained in:
Matthew Brown 2017-02-01 18:27:24 -05:00
parent 2852eeebad
commit 1051ba9fc1

View File

@ -126,6 +126,11 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
*/
protected static $class_extends = [];
/**
* @var PhpParser\Node\Stmt[]
*/
protected $leftover_stmts = [];
/**
* @param PhpParser\Node\Stmt\ClassLike $class
* @param StatementsSource $source
@ -183,8 +188,6 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
$storage->user_defined = true;
$leftover_stmts = [];
$long_file_name = $this->source->getFilePath();
if (!$class_context) {
@ -277,6 +280,8 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
}
}
$const_stmts = [];
foreach ($this->class->stmts as $stmt) {
if ($stmt instanceof PhpParser\Node\Stmt\ClassMethod) {
$this->visitClassMethod(
@ -294,14 +299,14 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
$class_context,
$config
);
$leftover_stmts[] = $stmt;
$this->leftover_stmts[] = $stmt;
} elseif ($stmt instanceof PhpParser\Node\Stmt\ClassConst) {
$this->visitClassConstDeclaration(
$stmt,
$class_context,
$config
);
$leftover_stmts[] = $stmt;
$const_stmts[] = $stmt;
}
}
@ -309,8 +314,8 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
$this->has_custom_get = true;
}
if ($leftover_stmts) {
(new StatementsChecker($this))->analyze($leftover_stmts, $class_context);
if ($const_stmts) {
(new StatementsChecker($this))->analyze($const_stmts, $class_context);
}
$config = Config::getInstance();
@ -432,6 +437,10 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
$class_context->parent = $this->parent_fq_class_name;
}
if ($this->leftover_stmts) {
(new StatementsChecker($this))->analyze($this->leftover_stmts, $class_context);
}
$available_properties = [];
foreach ($storage->appearing_property_ids as $property_name => $appearing_property_id) {