rector/packages/Comments/CommentRemover.php
Tomas Votruba 1f63ed3e55
Reworking trait scope run (#952)
* try reworking trait scope run

* load configs from extension installer

* add trait type

* load configs from extension installer in PHPStan internally in Rector too

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
2021-10-04 23:11:10 +02:00

45 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Rector\Comments;
use PhpParser\Comment;
use PhpParser\Comment\Doc;
use PhpParser\Node;
use Rector\Comments\NodeTraverser\CommentRemovingNodeTraverser;
use Rector\NodeTypeResolver\Node\AttributeKey;
/**
* @see \Rector\Tests\Comments\CommentRemover\CommentRemoverTest
*/
final class CommentRemover
{
public function __construct(
private CommentRemovingNodeTraverser $commentRemovingNodeTraverser
) {
}
/**
* @return Node[]|null
*/
public function removeFromNode(array | Node | null $node): array | null
{
if ($node === null) {
return null;
}
$copiedNodes = $node;
$nodes = is_array($copiedNodes) ? $copiedNodes : [$copiedNodes];
return $this->commentRemovingNodeTraverser->traverse($nodes);
}
public function rollbackComments(Node $node, Comment $comment): void
{
$node->setAttribute(AttributeKey::COMMENTS, null);
$node->setDocComment(new Doc($comment->getText()));
$node->setAttribute(AttributeKey::PHP_DOC_INFO, null);
}
}