1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Rely on call map more

This commit is contained in:
Matthew Brown 2016-11-06 23:29:54 -05:00
parent b744ba547a
commit 8d0a8ab055
3 changed files with 38 additions and 9 deletions

View File

@ -669,6 +669,7 @@ abstract class ClassLikeChecker implements StatementsSource
MethodChecker::registerClassMethod($method_id);
/** @var string */
$declaring_method_id = MethodChecker::getDeclaringMethodId($method_id);
$declaring_class = explode('::', $declaring_method_id)[0];
@ -1134,6 +1135,7 @@ abstract class ClassLikeChecker implements StatementsSource
foreach ($class_methods as $method_name => $_) {
$parent_method_id = $parent_class . '::' . $method_name;
/** @var string */
$declaring_method_id = MethodChecker::getDeclaringMethodId($parent_method_id);
$implemented_method_id = $this->absolute_class . '::' . $method_name;

View File

@ -140,6 +140,10 @@ abstract class FunctionLikeChecker implements StatementsSource
$function_params = MethodChecker::getMethodParams((string)$this->getMethodId());
if ($function_params === null) {
throw new \InvalidArgumentException('Cannot get params for own method');
}
$implemented_method_ids = MethodChecker::getOverriddenMethodIds((string)$this->getMethodId());
if ($implemented_method_ids) {
@ -156,6 +160,10 @@ abstract class FunctionLikeChecker implements StatementsSource
$implemented_params = MethodChecker::getMethodParams($implemented_method_id);
if ($implemented_params === null) {
continue;
}
foreach ($implemented_params as $i => $implemented_param) {
if (!isset($function_params[$i])) {
$cased_method_id = MethodChecker::getCasedMethodId((string)$this->getMethodId());
@ -931,13 +939,27 @@ abstract class FunctionLikeChecker implements StatementsSource
$absolute_class = strpos($method_id, '::') !== false ? explode('::', $method_id)[0] : null;
if ($absolute_class && ClassLikeChecker::isUserDefined($absolute_class)) {
/** @var array<\Psalm\FunctionLikeParameter> */
return MethodChecker::getMethodParams($method_id);
} elseif (!$absolute_class && FunctionChecker::inCallMap($method_id)) {
/** @var array<array<FunctionLikeParameter>> */
$function_param_options = FunctionChecker::getParamsFromCallMap($method_id);
} elseif ($absolute_class) {
// fall back to using reflected params anyway
return MethodChecker::getMethodParams($method_id);
if ($method_params = MethodChecker::getMethodParams($method_id)) {
// fall back to using reflected params anyway
return $method_params;
}
$declaring_method_id = MethodChecker::getDeclaringMethodId($method_id);
$method_id = $declaring_method_id ?: $method_id;
if (!FunctionChecker::inCallMap($method_id)) {
throw new \InvalidArgumentException('Cannot get params for ' . $method_id);
}
/** @var array<array<FunctionLikeParameter>> */
$function_param_options = FunctionChecker::getParamsFromCallMap($method_id);
} else {
return FunctionChecker::getParams(strtolower($method_id), $file_name);
}

View File

@ -110,15 +110,15 @@ class MethodChecker extends FunctionLikeChecker
/**
* @param string $method_id
* @return array<\Psalm\FunctionLikeParameter>
* @return array<\Psalm\FunctionLikeParameter>|null
*/
public static function getMethodParams($method_id)
{
self::registerClassMethod($method_id);
$method_id = self::getDeclaringMethodId($method_id);
return self::$method_params[$method_id];
if ($method_id = self::getDeclaringMethodId($method_id)) {
return self::$method_params[$method_id];
}
}
/**
@ -142,6 +142,7 @@ class MethodChecker extends FunctionLikeChecker
{
self::registerClassMethod($method_id);
/** @var string */
$method_id = self::getDeclaringMethodId($method_id);
if (self::$method_return_types[$method_id]) {
@ -229,6 +230,7 @@ class MethodChecker extends FunctionLikeChecker
{
self::registerClassMethod($method_id);
/** @var string */
$method_id = self::getDeclaringMethodId($method_id);
if (!self::$static_methods[$method_id]) {
@ -620,12 +622,15 @@ class MethodChecker extends FunctionLikeChecker
/**
* @param string $method_id
* @return string
* @return void
* @return string|null
*/
public static function getDeclaringMethodId($method_id)
{
return self::$declaring_methods[$method_id];
if (isset(self::$declaring_methods[$method_id])) {
return self::$declaring_methods[$method_id];
}
return null;
}
/**