1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +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; $is_static = false;
$has_return = false;
if (!preg_match('/^([a-z_A-Z][a-z_0-9A-Z]+) *\(/', $method_entry, $matches)) { if (!preg_match('/^([a-z_A-Z][a-z_0-9A-Z]+) *\(/', $method_entry, $matches)) {
$doc_line_parts = self::splitDocLine($method_entry); $doc_line_parts = self::splitDocLine($method_entry);
@ -938,6 +940,7 @@ class CommentAnalyzer
if (count($doc_line_parts) > 1) { if (count($doc_line_parts) > 1) {
$docblock_lines[] = '@return ' . array_shift($doc_line_parts); $docblock_lines[] = '@return ' . array_shift($doc_line_parts);
$has_return = true;
$method_entry = implode(' ', $doc_line_parts); $method_entry = implode(' ', $doc_line_parts);
} }
@ -983,10 +986,13 @@ class CommentAnalyzer
} }
if ($method_tree instanceof ParseTree\MethodWithReturnTypeTree) { if ($method_tree instanceof ParseTree\MethodWithReturnTypeTree) {
if (!$has_return) {
$docblock_lines[] = '@return ' . TypeParser::getTypeFromTree( $docblock_lines[] = '@return ' . TypeParser::getTypeFromTree(
$method_tree->children[1], $method_tree->children[1],
$codebase $codebase
)->toNamespacedString($aliases->namespace, $aliases->uses, null, false); )->toNamespacedString($aliases->namespace, $aliases->uses, null, false);
}
$method_tree = $method_tree->children[0]; $method_tree = $method_tree->children[0];
} }

View File

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