2019-07-05 22:24:00 +02:00
|
|
|
<?php
|
2021-12-15 04:42:37 +01:00
|
|
|
|
2019-07-05 22:24:00 +02:00
|
|
|
declare(strict_types=1);
|
2021-12-15 04:42:37 +01:00
|
|
|
|
2020-03-15 04:54:42 +01:00
|
|
|
namespace Psalm\Internal\PhpVisitor;
|
2018-10-26 06:59:14 +02:00
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
use PhpParser\Comment;
|
2018-10-26 06:59:14 +02:00
|
|
|
use PhpParser\Node;
|
|
|
|
use PhpParser\NodeVisitorAbstract;
|
|
|
|
|
2021-06-08 04:55:21 +02:00
|
|
|
use function array_map;
|
|
|
|
|
2018-10-26 06:59:14 +02:00
|
|
|
/**
|
|
|
|
* Visitor cloning all nodes and linking to the original nodes using an attribute.
|
|
|
|
*
|
|
|
|
* This visitor is required to perform format-preserving pretty prints.
|
2022-01-03 07:55:32 +01:00
|
|
|
*
|
|
|
|
* @internal
|
2018-10-26 06:59:14 +02:00
|
|
|
*/
|
|
|
|
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(
|
|
|
|
/**
|
2021-12-04 03:37:19 +01:00
|
|
|
* @return Comment
|
2018-10-28 02:21:57 +01:00
|
|
|
*/
|
2021-12-03 20:11:20 +01:00
|
|
|
function (Comment $c): 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;
|
|
|
|
}
|
|
|
|
}
|