Skip to content

Commit

Permalink
Avoid regenerating docblock when no modification is made (#3374)
Browse files Browse the repository at this point in the history
* Avoid regenerating docblock when no modification is made

* Generate empty docblock before, in case there was no docblock at all
  • Loading branch information
orklah committed May 16, 2020
1 parent f824cc3 commit dd4927a
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ private function getDocblock()
$parsed_docblock = ['description' => '', 'specials' => []];
}

$modified_docblock = false;

foreach ($this->new_phpdoc_param_types as $param_name => $phpdoc_type) {
$found_in_params = false;
$new_param_block = $phpdoc_type . ' ' . '$' . $param_name;
Expand All @@ -334,6 +336,7 @@ private function getDocblock()
$doc_parts = CommentAnalyzer::splitDocLine($param_block);

if (($doc_parts[1] ?? null) === '$' . $param_name) {
$modified_docblock = true;
$param_block = $new_param_block;
$found_in_params = true;
break;
Expand All @@ -342,25 +345,32 @@ private function getDocblock()
}

if (!$found_in_params) {
$modified_docblock = true;
$parsed_docblock['specials']['param'][] = $new_param_block;
}
}

if ($this->new_phpdoc_return_type) {
$modified_docblock = true;
$parsed_docblock['specials']['return'] = [
$this->new_phpdoc_return_type
. ($this->return_type_description ? (' ' . $this->return_type_description) : ''),
];
}

if ($this->new_phpdoc_return_type !== $this->new_psalm_return_type && $this->new_psalm_return_type) {
$modified_docblock = true;
$parsed_docblock['specials']['psalm-return'] = [$this->new_psalm_return_type];
}

if (!$parsed_docblock['specials'] && !$parsed_docblock['description']) {
return '';
}

if (!$modified_docblock) {
return (string)$docblock . "\n" . $this->indentation;
}

return DocComment::render($parsed_docblock, $this->indentation);
}

Expand Down

0 comments on commit dd4927a

Please sign in to comment.