mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
[DeadDocBlock] Skip RemoveNonExistingVarAnnotationRector on has other comment before var (#4988)
Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
parent
d4883d44d9
commit
3ef72c375f
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user