1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Don’t add two @return docblocks after @method

This commit is contained in:
Brown 2020-06-20 15:30:47 -04:00
parent edbeec2c6a
commit 2c5c9e95e1
2 changed files with 15 additions and 6 deletions

View File

@ -928,6 +928,8 @@ class CommentAnalyzer
$is_static = false;
$has_return = false;
if (!preg_match('/^([a-z_A-Z][a-z_0-9A-Z]+) *\(/', $method_entry, $matches)) {
$doc_line_parts = self::splitDocLine($method_entry);
@ -938,6 +940,7 @@ class CommentAnalyzer
if (count($doc_line_parts) > 1) {
$docblock_lines[] = '@return ' . array_shift($doc_line_parts);
$has_return = true;
$method_entry = implode(' ', $doc_line_parts);
}
@ -983,10 +986,13 @@ class CommentAnalyzer
}
if ($method_tree instanceof ParseTree\MethodWithReturnTypeTree) {
$docblock_lines[] = '@return ' . TypeParser::getTypeFromTree(
$method_tree->children[1],
$codebase
)->toNamespacedString($aliases->namespace, $aliases->uses, null, false);
if (!$has_return) {
$docblock_lines[] = '@return ' . TypeParser::getTypeFromTree(
$method_tree->children[1],
$codebase
)->toNamespacedString($aliases->namespace, $aliases->uses, null, false);
}
$method_tree = $method_tree->children[0];
}

View File

@ -624,12 +624,15 @@ class MagicMethodAnnotationTest extends TestCase
interface FooInterface {}
/**
* @method getAll():\IteratorAggregate
* @method \IteratorAggregate<int, FooInterface> getAll():\IteratorAggregate
*/
class Foo
{
private \IteratorAggregate $items;
/**
* @psalm-suppress MixedReturnTypeCoercion
*/
public function getAll(): \IteratorAggregate
{
return $this->items;
@ -643,7 +646,7 @@ class MagicMethodAnnotationTest extends TestCase
/**
* @psalm-suppress MixedReturnTypeCoercion
* @method \IteratorAggregate<int, FooInterface> getAll()
* @method \IteratorAggregate<int, FooInterface> getAll():\IteratorAggregate
*/
class Bar
{