[DeadDocBlock] Skip RemoveNonExistingVarAnnotationRector on has other comment before var (#4988)

Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
Abdul Malik Ikhsan 2020-12-26 17:30:52 +07:00 committed by GitHub
parent d4883d44d9
commit 3ef72c375f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
namespace Rector\DeadDocBlock\Rector\Node;
use Nette\Utils\Strings;
use PhpParser\Comment;
use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\AssignRef;
@ -118,8 +120,16 @@ CODE_SAMPLE
return null;
}
$phpDocInfo->removeByType(VarTagValueNode::class);
$comments = $node->getComments();
if (isset($comments[1]) && $comments[1] instanceof Comment) {
$node->setAttribute(AttributeKey::COMMENTS, null);
$node->setDocComment(new Doc($comments[1]->getText()));
$node->setAttribute(AttributeKey::PHP_DOC_INFO, null);
return $node;
}
$phpDocInfo->removeByType(VarTagValueNode::class);
return $node;
}

View File

@ -0,0 +1,30 @@
<?php
namespace Rector\DeadDocBlock\Tests\Rector\Node\RemoveNonExistingVarAnnotationRector\Fixture;
class OtherCommentBeforeVar
{
public function get()
{
/** @var \stdClass $nonExisting */
// Load data also with projekt...
$return[] = $this->getReturnData();
}
}
?>
-----
<?php
namespace Rector\DeadDocBlock\Tests\Rector\Node\RemoveNonExistingVarAnnotationRector\Fixture;
class OtherCommentBeforeVar
{
public function get()
{
// Load data also with projekt...
$return[] = $this->getReturnData();
}
}
?>