mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 03:40:50 +00:00
1f63ed3e55
* 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>
45 lines
1.1 KiB
PHP
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);
|
|
}
|
|
}
|