Skip to content

Commit

Permalink
[TypeDeclaration] Do not remove docblock with description on MergeDat…
Browse files Browse the repository at this point in the history
…eTimePropertyTypeDeclarationRector (#5931)

* [TypeDeclaration] Do not remove docblock with description on MergeDateTimePropertyTypeDeclarationRector

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed May 30, 2024
1 parent b2d1c9d commit a3ed07f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Class_\MergeDateTimePropertyTypeDeclarationRector\Fixture;

final class DoNotRemoveDocWithDescription
{
/**
* @var \DateTimeInterface some desc
*/
private \DateTime $dateTime;
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Class_\MergeDateTimePropertyTypeDeclarationRector\Fixture;

final class DoNotRemoveDocWithDescription
{
/**
* @var \DateTimeInterface some desc
*/
private \DateTimeInterface $dateTime;
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ public function refactor(Node $node): ?Node
? $this->nodeTypeResolver->getFullyQualifiedClassName($varType)
: null;
if ($className === 'DateTimeInterface') {
$phpDocInfo->removeByType(VarTagValueNode::class);
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property);
$varTagvalueNode = $phpDocInfo->getVarTagValueNode();
if ($varTagvalueNode instanceof VarTagValueNode && $varTagvalueNode->description === '') {
$phpDocInfo->removeByType(VarTagValueNode::class);
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property);
}

$property->type = new FullyQualified('DateTimeInterface');
$hasChanged = true;
Expand Down

0 comments on commit a3ed07f

Please sign in to comment.