1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-11 07:31:45 +01:00
psalm/src/Psalm/Internal/PhpVisitor/ConditionCloningVisitor.php

43 lines
835 B
PHP
Raw Normal View History

<?php
2021-12-15 04:42:37 +01: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;
use PhpParser\Node;
2021-12-04 03:37:19 +01:00
use PhpParser\Node\Expr;
use PhpParser\NodeVisitorAbstract;
2021-12-03 20:11:20 +01:00
use Psalm\Internal\Provider\NodeDataProvider;
2022-01-03 07:55:32 +01:00
/**
* @internal
*/
class ConditionCloningVisitor extends NodeVisitorAbstract
{
2022-12-11 23:26:05 +01:00
private NodeDataProvider $type_provider;
2021-12-03 20:11:20 +01:00
public function __construct(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
{
2021-12-04 03:37:19 +01:00
/** @var Expr $node */
2020-08-10 05:19:59 +02:00
$origNode = $node;
$node = clone $node;
$node_type = $this->type_provider->getType($origNode);
if ($node_type) {
$this->type_provider->setType($node, $node_type);
}
return $node;
}
}