1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-10 23:18:40 +01:00
psalm/src/Psalm/Internal/PhpVisitor/ConditionCloningVisitor.php

36 lines
771 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
2020-03-15 04:54:42 +01:00
namespace Psalm\Internal\PhpVisitor;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
class ConditionCloningVisitor extends NodeVisitorAbstract
{
private $type_provider;
public function __construct(\Psalm\Internal\Provider\NodeDataProvider $old_type_provider)
{
$this->type_provider = $old_type_provider;
}
2020-10-17 18:36:44 +02:00
/**
* @return Node\Expr
*/
public function enterNode(Node $node): Node
{
2020-08-10 05:19:59 +02:00
/** @var \PhpParser\Node\Expr $node */
$origNode = $node;
$node = clone $node;
$node_type = $this->type_provider->getType($origNode);
if ($node_type) {
$this->type_provider->setType($node, clone $node_type);
}
return $node;
}
}