1
0
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:
Matthew Brown 2016-10-25 11:40:09 -04:00
parent 694d159829
commit 4d224d56db
2 changed files with 25 additions and 6 deletions

View File

@ -154,6 +154,13 @@ abstract class ClassLikeChecker implements StatementsSource
*/ */
protected static $registered_classes = []; 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 * A lookup table used for storing the results of ClassChecker::classImplements
* *
@ -195,6 +202,7 @@ abstract class ClassLikeChecker implements StatementsSource
$config = Config::getInstance(); $config = Config::getInstance();
self::$registered_classes[$this->absolute_class] = true; self::$registered_classes[$this->absolute_class] = true;
self::$user_defined[$this->absolute_class] = true;
$leftover_stmts = []; $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]) : []; 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() public static function clearCache()
{ {
self::$this_class = null; self::$this_class = null;

View File

@ -800,14 +800,19 @@ abstract class FunctionLikeChecker implements StatementsSource
*/ */
public static function getParamsById($method_id, array $args, $file_name) public static function getParamsById($method_id, array $args, $file_name)
{ {
if (FunctionChecker::inCallMap($method_id) || !strpos($method_id, '::')) { $absolute_class = strpos($method_id, '::') ? explode($method_id, '::')[0] : null;
$function_param_options = FunctionChecker::getParamsFromCallMap($method_id);
} if ($absolute_class && ClassLikeChecker::isUserDefined($absolute_class)) {
else {
return MethodChecker::getMethodParams($method_id); return MethodChecker::getMethodParams($method_id);
} }
elseif (!$absolute_class && FunctionChecker::inCallMap($method_id)) {
if ($function_param_options === null) { $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); return FunctionChecker::getParams(strtolower($method_id), $file_name);
} }