diff --git a/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php b/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php index 931b9c5ab..011c10cdb 100644 --- a/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php +++ b/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php @@ -2,6 +2,7 @@ namespace Psalm\Internal\FileManipulation; use PhpParser; +use function array_shift; use function count; use function ltrim; use PhpParser\Node\Expr\ArrowFunction; @@ -336,7 +337,10 @@ class FunctionDocblockManipulator $doc_parts = CommentAnalyzer::splitDocLine($param_block); if (($doc_parts[1] ?? null) === '$' . $param_name) { - $modified_docblock = true; + if ($param_block !== $new_param_block) { + $modified_docblock = true; + } + $param_block = $new_param_block; $found_in_params = true; 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; $parsed_docblock['specials']['return'] = [ $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; $parsed_docblock['specials']['psalm-return'] = [$this->new_psalm_return_type]; }