2019-07-05 22:24:00 +02:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
2020-03-15 04:54:42 +01:00
|
|
|
namespace Psalm\Internal\PhpVisitor;
|
2018-10-26 06:59:14 +02:00
|
|
|
|
2019-07-05 22:24:00 +02:00
|
|
|
use function array_map;
|
2018-10-26 06:59:14 +02:00
|
|
|
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
|
|
|
|
{
|
2020-09-12 17:24:05 +02:00
|
|
|
public function enterNode(Node $node): Node
|
2018-10-26 06:59:14 +02:00
|
|
|
{
|
2020-08-10 05:19:59 +02:00
|
|
|
$node = clone $node;
|
2018-10-28 02:21:57 +01:00
|
|
|
if ($cs = $node->getComments()) {
|
|
|
|
$node->setAttribute(
|
|
|
|
'comments',
|
|
|
|
array_map(
|
|
|
|
/**
|
|
|
|
* @return \PhpParser\Comment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
function (\PhpParser\Comment $c): \PhpParser\Comment {
|
2018-10-28 02:21:57 +01:00
|
|
|
return clone $c;
|
|
|
|
},
|
|
|
|
$cs
|
|
|
|
)
|
|
|
|
);
|
2018-10-26 06:59:14 +02:00
|
|
|
}
|
2019-07-05 22:24:00 +02:00
|
|
|
|
2018-10-26 06:59:14 +02:00
|
|
|
return $node;
|
|
|
|
}
|
|
|
|
}
|