2019-11-25 17:44:54 +01:00
|
|
|
<?php
|
2021-12-15 04:42:37 +01:00
|
|
|
|
2019-11-25 17:44:54 +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;
|
2019-11-25 17:44:54 +01:00
|
|
|
|
|
|
|
use PhpParser\Node;
|
2021-12-04 03:37:19 +01:00
|
|
|
use PhpParser\Node\Expr;
|
2019-11-25 17:44:54 +01:00
|
|
|
use PhpParser\NodeVisitorAbstract;
|
2021-12-03 20:11:20 +01:00
|
|
|
use Psalm\Internal\Provider\NodeDataProvider;
|
2019-11-25 17:44:54 +01:00
|
|
|
|
|
|
|
class ConditionCloningVisitor extends NodeVisitorAbstract
|
|
|
|
{
|
|
|
|
private $type_provider;
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
public function __construct(NodeDataProvider $old_type_provider)
|
2019-11-25 17:44:54 +01:00
|
|
|
{
|
|
|
|
$this->type_provider = $old_type_provider;
|
|
|
|
}
|
|
|
|
|
2020-10-17 18:36:44 +02:00
|
|
|
/**
|
|
|
|
* @return Node\Expr
|
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function enterNode(Node $node): Node
|
2019-11-25 17:44:54 +01:00
|
|
|
{
|
2021-12-04 03:37:19 +01:00
|
|
|
/** @var Expr $node */
|
2020-08-10 05:19:59 +02:00
|
|
|
$origNode = $node;
|
|
|
|
|
|
|
|
$node = clone $node;
|
2019-11-25 17:44:54 +01:00
|
|
|
|
|
|
|
$node_type = $this->type_provider->getType($origNode);
|
|
|
|
|
|
|
|
if ($node_type) {
|
|
|
|
$this->type_provider->setType($node, clone $node_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $node;
|
|
|
|
}
|
|
|
|
}
|