1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00

Catch bad docblock issue

This commit is contained in:
Matthew Brown 2016-10-28 10:54:20 -04:00
parent 0b0a5ff0e8
commit b627bdf9c6
2 changed files with 98 additions and 62 deletions

View File

@ -167,47 +167,66 @@ class FunctionChecker extends FunctionLikeChecker
$config = Config::getInstance(); $config = Config::getInstance();
$return_type = null; $return_type = null;
$docblock_info = CommentChecker::extractDocblockInfo((string)$function->getDocComment()); $docblock_info = null;
if ($docblock_info['deprecated']) { $this->suppressed_issues = [];
self::$deprecated_functions[$file_name][$function_id] = true;
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']) { if ($docblock_info) {
self::$variadic_functions[$file_name][$function_id] = true; if ($docblock_info['deprecated']) {
} self::$deprecated_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']) { if ($docblock_info['variadic']) {
$this->improveParamsFromDocblock( self::$variadic_functions[$file_name][$function_id] = true;
$docblock_info['params'], }
$function_param_names,
self::$file_function_params[$file_name][$function_id], $this->suppressed_issues = $docblock_info['suppress'];
$function->getLine()
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; self::$function_return_types[$file_name][$function_id] = $return_type ?: false;

View File

@ -260,39 +260,56 @@ class MethodChecker extends FunctionLikeChecker
} }
if ($doc_comment) { if ($doc_comment) {
$docblock_info = CommentChecker::extractDocblockInfo((string)$doc_comment); $docblock_info = null;
if ($docblock_info['deprecated']) { try {
self::$deprecated_methods[$method_id] = true; $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']) { if ($docblock_info) {
self::$variadic_methods[$method_id] = true; if ($docblock_info['deprecated']) {
} self::$deprecated_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']) { if ($docblock_info['variadic']) {
$this->improveParamsFromDocblock( self::$variadic_methods[$method_id] = true;
$docblock_info['params'], }
$method_param_names,
self::$method_params[$method_id], $this->suppressed_issues = $docblock_info['suppress'];
$method->getLine() 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()
);
}
} }
} }
} }