1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Check constructors

This commit is contained in:
Matthew Brown 2016-01-07 23:40:29 -05:00
parent a9c7c6904c
commit 8701c6a26e

View File

@ -448,18 +448,22 @@ class FunctionChecker
protected function _checkNew(PhpParser\Node\Expr\New_ $stmt, array &$types_in_scope) protected function _checkNew(PhpParser\Node\Expr\New_ $stmt, array &$types_in_scope)
{ {
$absolute_class = null;
if ($stmt->class instanceof PhpParser\Node\Name && !in_array($stmt->class->parts[0], ['self', 'static', 'parent'])) { if ($stmt->class instanceof PhpParser\Node\Name && !in_array($stmt->class->parts[0], ['self', 'static', 'parent'])) {
if ($this->_check_classes) { if ($this->_check_classes) {
ClassChecker::checkClassName($stmt->class, $this->_namespace, $this->_aliased_classes, $this->_file_name); ClassChecker::checkClassName($stmt->class, $this->_namespace, $this->_aliased_classes, $this->_file_name);
$stmt->returnType = ClassChecker::getAbsoluteClassFromName($stmt->class, $this->_namespace, $this->_aliased_classes);
$absolute_class = ClassChecker::getAbsoluteClassFromName($stmt->class, $this->_namespace, $this->_aliased_classes);
$stmt->returnType = $absolute_class;
} }
} }
foreach ($stmt->args as $arg) { if ($absolute_class) {
$this->_checkExpression($arg->value, $types_in_scope); $method_id = $absolute_class . '::__construct';
$this->_checkMethodParams($stmt->args, $method_id, $types_in_scope);
} }
} }
protected function _checkArray(PhpParser\Node\Expr\Array_ $stmt, array &$types_in_scope) protected function _checkArray(PhpParser\Node\Expr\Array_ $stmt, array &$types_in_scope)
@ -471,6 +475,8 @@ class FunctionChecker
$this->_checkExpression($item->value, $types_in_scope); $this->_checkExpression($item->value, $types_in_scope);
} }
$stmt->returnType = 'array';
} }
protected function _checkTryCatch(PhpParser\Node\Stmt\TryCatch $stmt, array &$types_in_scope) protected function _checkTryCatch(PhpParser\Node\Stmt\TryCatch $stmt, array &$types_in_scope)
@ -1098,7 +1104,7 @@ class FunctionChecker
self::$_method_param_types[$method_id] = []; self::$_method_param_types[$method_id] = [];
foreach ($params as $param) { foreach ($params as $param) {
self::$_method_params[$method_id][] = $param->isPassedByReference(); self::$_method_params[$method_id][] = $param->isPassedByReference();
self::$_method_param_types[$method_id][] = $param->getClass() ? '\\' . $param->getClass()->getName() : null; self::$_method_param_types[$method_id][] = $param->getClass() ? '\\' . $param->getClass()->getName() : ($param->isArray() ? 'array' : null);
} }
self::$_method_comments[$method_id] = $method->getDocComment() ?: ''; self::$_method_comments[$method_id] = $method->getDocComment() ?: '';