mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Handle user-defined code in root namespace (e.g. OAuth) better
This commit is contained in:
parent
694d159829
commit
4d224d56db
@ -154,6 +154,13 @@ abstract class ClassLikeChecker implements StatementsSource
|
||||
*/
|
||||
protected static $registered_classes = [];
|
||||
|
||||
/**
|
||||
* A lookup table to record which classes are user-defined
|
||||
*
|
||||
* @var array<string,bool>
|
||||
*/
|
||||
protected static $user_defined = [];
|
||||
|
||||
/**
|
||||
* A lookup table used for storing the results of ClassChecker::classImplements
|
||||
*
|
||||
@ -195,6 +202,7 @@ abstract class ClassLikeChecker implements StatementsSource
|
||||
$config = Config::getInstance();
|
||||
|
||||
self::$registered_classes[$this->absolute_class] = true;
|
||||
self::$user_defined[$this->absolute_class] = true;
|
||||
|
||||
$leftover_stmts = [];
|
||||
|
||||
@ -1021,6 +1029,12 @@ abstract class ClassLikeChecker implements StatementsSource
|
||||
return isset(self::$file_classes[$file_name]) ? array_unique(self::$file_classes[$file_name]) : [];
|
||||
}
|
||||
|
||||
public static function isUserDefined($absolute_class)
|
||||
{
|
||||
self::registerClass($absolute_class);
|
||||
return isset(self::$user_defined[$absolute_class]);
|
||||
}
|
||||
|
||||
public static function clearCache()
|
||||
{
|
||||
self::$this_class = null;
|
||||
|
@ -800,14 +800,19 @@ abstract class FunctionLikeChecker implements StatementsSource
|
||||
*/
|
||||
public static function getParamsById($method_id, array $args, $file_name)
|
||||
{
|
||||
if (FunctionChecker::inCallMap($method_id) || !strpos($method_id, '::')) {
|
||||
$function_param_options = FunctionChecker::getParamsFromCallMap($method_id);
|
||||
}
|
||||
else {
|
||||
$absolute_class = strpos($method_id, '::') ? explode($method_id, '::')[0] : null;
|
||||
|
||||
if ($absolute_class && ClassLikeChecker::isUserDefined($absolute_class)) {
|
||||
return MethodChecker::getMethodParams($method_id);
|
||||
}
|
||||
|
||||
if ($function_param_options === null) {
|
||||
elseif (!$absolute_class && FunctionChecker::inCallMap($method_id)) {
|
||||
$function_param_options = FunctionChecker::getParamsFromCallMap($method_id);
|
||||
}
|
||||
elseif ($absolute_class) {
|
||||
// fall back to using reflected params anyway
|
||||
return MethodChecker::getMethodParams($method_id);
|
||||
}
|
||||
else {
|
||||
return FunctionChecker::getParams(strtolower($method_id), $file_name);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user