mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Solve more cases when docblock rendering is not needed (#3387)
This commit is contained in:
parent
b0ffaf0077
commit
3e7f5df7e1
@ -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) {
|
||||||
$modified_docblock = true;
|
if ($param_block !== $new_param_block) {
|
||||||
|
$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];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user