mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 01:40:49 +00:00
335ab50008
2d99c8b366
Remove removeNode() from InlineConstructorDefaultToPropertyRector (#4062)
31 lines
961 B
PHP
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;
|
|
}
|
|
}
|