1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-15 10:57:08 +01:00
psalm/src/Psalm/Internal/PhpVisitor/CloningVisitor.php
orklah ead107fa9e
More return types (#4173)
* add native return types

* redundant phpdoc
2020-09-12 11:24:05 -04:00

37 lines
914 B
PHP

<?php
declare(strict_types=1);
namespace Psalm\Internal\PhpVisitor;
use function array_map;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
/**
* Visitor cloning all nodes and linking to the original nodes using an attribute.
*
* This visitor is required to perform format-preserving pretty prints.
*/
class CloningVisitor extends NodeVisitorAbstract
{
public function enterNode(Node $node): Node
{
$node = clone $node;
if ($cs = $node->getComments()) {
$node->setAttribute(
'comments',
array_map(
/**
* @return \PhpParser\Comment
*/
function (\PhpParser\Comment $c): \PhpParser\Comment {
return clone $c;
},
$cs
)
);
}
return $node;
}
}