From ad38a26524e8b0b4e9dc058323adeb871e40e0da Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 15 Jan 2017 10:24:38 -0500 Subject: [PATCH] Hoist class check above method check --- .../Expression/AssignmentChecker.php | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php b/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php index 014d90a2e..2977dc0fa 100644 --- a/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php +++ b/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php @@ -471,31 +471,13 @@ class AssignmentChecker return null; } - if (MethodChecker::methodExists($lhs_type_part . '::__set')) { - $context->vars_in_scope[$var_id] = Type::getMixed(); - continue; - } - - $has_regular_setter = true; - if (ExpressionChecker::isMock($lhs_type_part->value)) { + $has_regular_setter = true; $context->vars_in_scope[$var_id] = Type::getMixed(); return null; } - if (($stmt->var instanceof PhpParser\Node\Expr\Variable && $stmt->var->name === 'this') - || $lhs_type_part->value === $context->self - ) { - $class_visibility = \ReflectionProperty::IS_PRIVATE; - } elseif ($context->self && - ClassChecker::classExtends($lhs_type_part->value, $context->self) - ) { - $class_visibility = \ReflectionProperty::IS_PROTECTED; - } else { - $class_visibility = \ReflectionProperty::IS_PUBLIC; - } - if (!ClassChecker::classExists($lhs_type_part->value, $file_checker)) { if (InterfaceChecker::interfaceExists($lhs_type_part->value, $file_checker)) { if (IssueBuffer::accepts( @@ -524,6 +506,25 @@ class AssignmentChecker return null; } + if (MethodChecker::methodExists($lhs_type_part . '::__set')) { + $context->vars_in_scope[$var_id] = Type::getMixed(); + continue; + } + + $has_regular_setter = true; + + if (($stmt->var instanceof PhpParser\Node\Expr\Variable && $stmt->var->name === 'this') + || $lhs_type_part->value === $context->self + ) { + $class_visibility = \ReflectionProperty::IS_PRIVATE; + } elseif ($context->self && + ClassChecker::classExtends($lhs_type_part->value, $context->self) + ) { + $class_visibility = \ReflectionProperty::IS_PROTECTED; + } else { + $class_visibility = \ReflectionProperty::IS_PUBLIC; + } + $property_id = $lhs_type_part->value . '::$' . $prop_name; if (!ClassLikeChecker::propertyExists($property_id)) {