Skip to content

Commit

Permalink
[BetterPhpDocParser] Call phpdocInfo->markAsChanged() on change param…
Browse files Browse the repository at this point in the history
…/return type on PhpDocTypeChanger (#3099)

* [BetterPhpDocParser] Call phpdocInfo->markasChanged() on change param/return type

* verify has changed usage on AddArrayParamDocTypeRector

* Fix PHPStan
  • Loading branch information
samsonasik committed Nov 26, 2022
1 parent f37a6eb commit 07b529a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function changeVarType(PhpDocInfo $phpDocInfo, Type $newType): void
if ($currentVarTagValueNode !== null) {
// only change type
$currentVarTagValueNode->type = $newPHPStanPhpDocType;
$phpDocInfo->markAsChanged();
} else {
// add completely new one
$varTagValueNode = new VarTagValueNode($newPHPStanPhpDocType, '', '');
Expand Down Expand Up @@ -117,6 +118,7 @@ public function changeReturnType(PhpDocInfo $phpDocInfo, Type $newType): bool
if ($currentReturnTagValueNode !== null) {
// only change type
$currentReturnTagValueNode->type = $newPHPStanPhpDocType;
$phpDocInfo->markAsChanged();
} else {
// add completely new one
$returnTagValueNode = new ReturnTagValueNode($newPHPStanPhpDocType, '');
Expand Down Expand Up @@ -154,6 +156,7 @@ public function changeParamType(PhpDocInfo $phpDocInfo, Type $newType, Param $pa
}

$paramTagValueNode->type = $phpDocType;
$phpDocInfo->markAsChanged();
} else {
$paramTagValueNode = $this->paramPhpDocNodeFactory->create($phpDocType, $param);
$phpDocInfo->addTagValueNode($paramTagValueNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public function refactor(Node $node): ?Node
}

$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
$hasChangedNode = false;

foreach ($node->getParams() as $param) {
if ($this->shouldSkipParam($param)) {
continue;
Expand All @@ -118,11 +116,9 @@ public function refactor(Node $node): ?Node

$paramName = $this->getName($param);
$this->phpDocTypeChanger->changeParamType($phpDocInfo, $paramType, $param, $paramName);

$hasChangedNode = true;
}

if ($phpDocInfo->hasChanged() && $hasChangedNode) {
if ($phpDocInfo->hasChanged()) {
$this->paramTagRemover->removeParamTagsIfUseless($phpDocInfo, $node);
return $node;
}
Expand Down

0 comments on commit 07b529a

Please sign in to comment.