1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-10 06:58:41 +01:00
psalm/src/Psalm/Internal/PhpVisitor/ConditionCloningVisitor.php
2022-12-11 17:25:23 -06:00

43 lines
835 B
PHP

<?php
declare(strict_types=1);
namespace Psalm\Internal\PhpVisitor;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\NodeVisitorAbstract;
use Psalm\Internal\Provider\NodeDataProvider;
/**
* @internal
*/
class ConditionCloningVisitor extends NodeVisitorAbstract
{
private NodeDataProvider $type_provider;
public function __construct(NodeDataProvider $old_type_provider)
{
$this->type_provider = $old_type_provider;
}
/**
* @return Node\Expr
*/
public function enterNode(Node $node): Node
{
/** @var Expr $node */
$origNode = $node;
$node = clone $node;
$node_type = $this->type_provider->getType($origNode);
if ($node_type) {
$this->type_provider->setType($node, $node_type);
}
return $node;
}
}