mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Catch bad docblock issue
This commit is contained in:
parent
0b0a5ff0e8
commit
b627bdf9c6
@ -167,47 +167,66 @@ class FunctionChecker extends FunctionLikeChecker
|
||||
$config = Config::getInstance();
|
||||
$return_type = null;
|
||||
|
||||
$docblock_info = CommentChecker::extractDocblockInfo((string)$function->getDocComment());
|
||||
$docblock_info = null;
|
||||
|
||||
if ($docblock_info['deprecated']) {
|
||||
self::$deprecated_functions[$file_name][$function_id] = true;
|
||||
$this->suppressed_issues = [];
|
||||
|
||||
try {
|
||||
$docblock_info = CommentChecker::extractDocblockInfo((string)$function->getDocComment());
|
||||
}
|
||||
catch (\Psalm\Exception\DocblockParseException $e) {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidDocblock(
|
||||
'Invalid type passed in docblock for ' . $this->getMethodId(),
|
||||
$this->getCheckedFileName(),
|
||||
$function->getLine()
|
||||
)
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($docblock_info['variadic']) {
|
||||
self::$variadic_functions[$file_name][$function_id] = true;
|
||||
}
|
||||
|
||||
$this->suppressed_issues = $docblock_info['suppress'];
|
||||
|
||||
if ($function->returnType) {
|
||||
$return_type = Type::parseString(
|
||||
is_string($function->returnType)
|
||||
? $function->returnType
|
||||
: ClassLikeChecker::getAbsoluteClassFromName($function->returnType, $this->namespace, $this->getAliasedClasses())
|
||||
);
|
||||
}
|
||||
|
||||
if ($config->use_docblock_types) {
|
||||
if ($docblock_info['return_type']) {
|
||||
$return_type =
|
||||
Type::parseString(
|
||||
self::fixUpLocalType(
|
||||
(string)$docblock_info['return_type'],
|
||||
null,
|
||||
$this->namespace,
|
||||
$this->getAliasedClasses()
|
||||
)
|
||||
);
|
||||
if ($docblock_info) {
|
||||
if ($docblock_info['deprecated']) {
|
||||
self::$deprecated_functions[$file_name][$function_id] = true;
|
||||
}
|
||||
|
||||
if ($docblock_info['params']) {
|
||||
$this->improveParamsFromDocblock(
|
||||
$docblock_info['params'],
|
||||
$function_param_names,
|
||||
self::$file_function_params[$file_name][$function_id],
|
||||
$function->getLine()
|
||||
if ($docblock_info['variadic']) {
|
||||
self::$variadic_functions[$file_name][$function_id] = true;
|
||||
}
|
||||
|
||||
$this->suppressed_issues = $docblock_info['suppress'];
|
||||
|
||||
if ($function->returnType) {
|
||||
$return_type = Type::parseString(
|
||||
is_string($function->returnType)
|
||||
? $function->returnType
|
||||
: ClassLikeChecker::getAbsoluteClassFromName($function->returnType, $this->namespace, $this->getAliasedClasses())
|
||||
);
|
||||
}
|
||||
|
||||
if ($config->use_docblock_types) {
|
||||
if ($docblock_info['return_type']) {
|
||||
$return_type =
|
||||
Type::parseString(
|
||||
self::fixUpLocalType(
|
||||
(string)$docblock_info['return_type'],
|
||||
null,
|
||||
$this->namespace,
|
||||
$this->getAliasedClasses()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($docblock_info['params']) {
|
||||
$this->improveParamsFromDocblock(
|
||||
$docblock_info['params'],
|
||||
$function_param_names,
|
||||
self::$file_function_params[$file_name][$function_id],
|
||||
$function->getLine()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self::$function_return_types[$file_name][$function_id] = $return_type ?: false;
|
||||
|
@ -260,39 +260,56 @@ class MethodChecker extends FunctionLikeChecker
|
||||
}
|
||||
|
||||
if ($doc_comment) {
|
||||
$docblock_info = CommentChecker::extractDocblockInfo((string)$doc_comment);
|
||||
$docblock_info = null;
|
||||
|
||||
if ($docblock_info['deprecated']) {
|
||||
self::$deprecated_methods[$method_id] = true;
|
||||
try {
|
||||
$docblock_info = CommentChecker::extractDocblockInfo((string)$doc_comment);
|
||||
}
|
||||
catch (\Psalm\Exception\DocblockParseException $e) {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidDocblock(
|
||||
'Invalid type passed in docblock for ' . $this->getMethodId(),
|
||||
$this->getCheckedFileName(),
|
||||
$function->getLine()
|
||||
)
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($docblock_info['variadic']) {
|
||||
self::$variadic_methods[$method_id] = true;
|
||||
}
|
||||
|
||||
$this->suppressed_issues = $docblock_info['suppress'];
|
||||
self::$method_suppress[$method_id] = $this->suppressed_issues;
|
||||
|
||||
if ($config->use_docblock_types) {
|
||||
if ($docblock_info['return_type']) {
|
||||
$return_type =
|
||||
Type::parseString(
|
||||
$this->fixUpLocalType(
|
||||
(string)$docblock_info['return_type'],
|
||||
$this->absolute_class,
|
||||
$this->namespace,
|
||||
$this->getAliasedClasses()
|
||||
)
|
||||
);
|
||||
if ($docblock_info) {
|
||||
if ($docblock_info['deprecated']) {
|
||||
self::$deprecated_methods[$method_id] = true;
|
||||
}
|
||||
|
||||
if ($docblock_info['params']) {
|
||||
$this->improveParamsFromDocblock(
|
||||
$docblock_info['params'],
|
||||
$method_param_names,
|
||||
self::$method_params[$method_id],
|
||||
$method->getLine()
|
||||
);
|
||||
if ($docblock_info['variadic']) {
|
||||
self::$variadic_methods[$method_id] = true;
|
||||
}
|
||||
|
||||
$this->suppressed_issues = $docblock_info['suppress'];
|
||||
self::$method_suppress[$method_id] = $this->suppressed_issues;
|
||||
|
||||
if ($config->use_docblock_types) {
|
||||
if ($docblock_info['return_type']) {
|
||||
$return_type =
|
||||
Type::parseString(
|
||||
$this->fixUpLocalType(
|
||||
(string)$docblock_info['return_type'],
|
||||
$this->absolute_class,
|
||||
$this->namespace,
|
||||
$this->getAliasedClasses()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($docblock_info['params']) {
|
||||
$this->improveParamsFromDocblock(
|
||||
$docblock_info['params'],
|
||||
$method_param_names,
|
||||
self::$method_params[$method_id],
|
||||
$method->getLine()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user