rector/packages/NodeRemoval/BreakingRemovalGuard.php
Tomas Votruba 335ab50008 Updated Rector to commit 2d99c8b3661934f33155ddb5d46e62c7ba14715a
2d99c8b366 Remove removeNode() from InlineConstructorDefaultToPropertyRector (#4062)
2023-06-04 17:26:50 +00:00

31 lines
961 B
PHP

<?php
declare (strict_types=1);
namespace Rector\NodeRemoval;
use PhpParser\Node;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class BreakingRemovalGuard
{
/**
* @deprecated
*/
public function ensureNodeCanBeRemove(Node $node) : void
{
if ($this->isLegalNodeRemoval($node)) {
return;
}
/** @var string $childOfNodeType */
$childOfNodeType = $node->getAttribute(AttributeKey::CHILD_OF_NODE_TYPE);
throw new ShouldNotHappenException(\sprintf('Node "%s" on line %d is child of "%s", so it cannot be removed as it would break PHP code. Change or remove the parent node instead.', \get_class($node), $node->getLine(), $childOfNodeType));
}
/**
* @api
*/
public function isLegalNodeRemoval(Node $node) : bool
{
return $node->getAttribute(AttributeKey::IS_BREAKING_REMOVAL_NODE) !== \true;
}
}