mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-12 22:22:24 +00:00
7b17dd2d5b
02b9331990
[Traverser] Add BreakingRemovalGuardNodeVisitor to reduce parent attribute usage on BreakingRemovalGuard (#3978)
34 lines
1.3 KiB
PHP
34 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Expr\BooleanNot;
|
|
use PhpParser\Node\Stmt\If_;
|
|
use PhpParser\Node\Stmt\While_;
|
|
use PhpParser\NodeVisitorAbstract;
|
|
use Rector\NodeTypeResolver\Node\AttributeKey;
|
|
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
|
|
final class BreakingRemovalGuardNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
|
|
{
|
|
public function enterNode(Node $node) : ?Node
|
|
{
|
|
if ($node instanceof If_) {
|
|
$node->cond->setAttribute(AttributeKey::IS_BREAKING_REMOVAL_NODE, \true);
|
|
$node->cond->setAttribute(AttributeKey::CHILD_OF_NODE_TYPE, If_::class);
|
|
return null;
|
|
}
|
|
if ($node instanceof BooleanNot) {
|
|
$node->expr->setAttribute(AttributeKey::IS_BREAKING_REMOVAL_NODE, \true);
|
|
$node->expr->setAttribute(AttributeKey::CHILD_OF_NODE_TYPE, BooleanNot::class);
|
|
return null;
|
|
}
|
|
if ($node instanceof While_) {
|
|
$node->cond->setAttribute(AttributeKey::IS_BREAKING_REMOVAL_NODE, \true);
|
|
$node->cond->setAttribute(AttributeKey::CHILD_OF_NODE_TYPE, While_::class);
|
|
}
|
|
return null;
|
|
}
|
|
}
|