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

Solve more cases when docblock rendering is not needed (#3387)

This commit is contained in:
orklah 2020-05-18 13:16:18 +02:00 committed by GitHub
parent b0ffaf0077
commit 3e7f5df7e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
namespace Psalm\Internal\FileManipulation; namespace Psalm\Internal\FileManipulation;
use PhpParser; use PhpParser;
use function array_shift;
use function count; use function count;
use function ltrim; use function ltrim;
use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\ArrowFunction;
@ -336,7 +337,10 @@ class FunctionDocblockManipulator
$doc_parts = CommentAnalyzer::splitDocLine($param_block); $doc_parts = CommentAnalyzer::splitDocLine($param_block);
if (($doc_parts[1] ?? null) === '$' . $param_name) { if (($doc_parts[1] ?? null) === '$' . $param_name) {
if ($param_block !== $new_param_block) {
$modified_docblock = true; $modified_docblock = true;
}
$param_block = $new_param_block; $param_block = $new_param_block;
$found_in_params = true; $found_in_params = true;
break; break;
@ -350,7 +354,14 @@ class FunctionDocblockManipulator
} }
} }
if ($this->new_phpdoc_return_type) { $old_phpdoc_return_type = null;
if (isset($parsed_docblock['specials']['return'])) {
$old_phpdoc_return_type = array_shift($parsed_docblock['specials']['return']);
}
if ($this->new_phpdoc_return_type
&& $this->new_phpdoc_return_type !== $old_phpdoc_return_type
) {
$modified_docblock = true; $modified_docblock = true;
$parsed_docblock['specials']['return'] = [ $parsed_docblock['specials']['return'] = [
$this->new_phpdoc_return_type $this->new_phpdoc_return_type
@ -358,7 +369,15 @@ class FunctionDocblockManipulator
]; ];
} }
if ($this->new_phpdoc_return_type !== $this->new_psalm_return_type && $this->new_psalm_return_type) { $old_psalm_return_type = null;
if (isset($parsed_docblock['specials']['psalm-return'])) {
$old_psalm_return_type = array_shift($parsed_docblock['specials']['psalm-return']);
}
if ($this->new_psalm_return_type
&& $this->new_phpdoc_return_type !== $this->new_psalm_return_type
&& $this->new_psalm_return_type !== $old_psalm_return_type
) {
$modified_docblock = true; $modified_docblock = true;
$parsed_docblock['specials']['psalm-return'] = [$this->new_psalm_return_type]; $parsed_docblock['specials']['psalm-return'] = [$this->new_psalm_return_type];
} }