From b0f6a020da84836989cc683ee6b090ad32873c19 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Tue, 9 Aug 2016 12:11:58 -0400 Subject: [PATCH] Exit early for invalid class or interface --- src/Psalm/StatementsChecker.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Psalm/StatementsChecker.php b/src/Psalm/StatementsChecker.php index 8466b90c3..0dfb98973 100644 --- a/src/Psalm/StatementsChecker.php +++ b/src/Psalm/StatementsChecker.php @@ -1348,8 +1348,38 @@ class StatementsChecker $class_visibility = \ReflectionProperty::IS_PUBLIC; } + if (!ClassChecker::classExists($lhs_type_part->value)) { + if (ClassChecker::interfaceExists($lhs_type_part->value)) { + if (IssueBuffer::accepts( + new NoInterfaceProperties( + 'Interfaces cannot have properties', + $this->_file_name, + $stmt->getLine() + ), + $this->_suppressed_issues + )) { + return false; + } + + return; + } + + if (IssueBuffer::accepts( + new UndefinedClass( + 'Cannot set properties of undefined class ' . $lhs_type_part->value, + $this->_file_name, + $stmt->getLine() + ), + $this->_suppressed_issues + )) { + return false; + } + + return; + } + $class_properties = ClassChecker::getInstancePropertiesForClass( - (string) $lhs_type_part, + $lhs_type_part->value, $class_visibility );