Skip to content

Commit

Permalink
Less doc, move from NodeRemover from AbstractRector - use directly or…
Browse files Browse the repository at this point in the history
… remove nodes right at the moment - that creates safer tree (#2741)
  • Loading branch information
TomasVotruba committed Aug 6, 2022
1 parent 6ad7b03 commit 86682e4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
14 changes: 1 addition & 13 deletions packages/NodeRemoval/NodeRemover.php
Expand Up @@ -96,7 +96,7 @@ public function removeParam(ClassMethod $classMethod, int | Param $keyOrParam):

public function removeArg(FuncCall | MethodCall | StaticCall $node, int $key): void
{
if ($node->args === null) {
if ($node->getArgs() === []) {
throw new ShouldNotHappenException();
}

Expand All @@ -110,16 +110,4 @@ public function removeArg(FuncCall | MethodCall | StaticCall $node, int $key): v

unset($node->args[$key]);
}

public function removeImplements(Class_ $class, int $key): void
{
if ($class->implements === null) {
throw new ShouldNotHappenException();
}

// notify about remove node
$this->rectorChangeCollector->notifyNodeFileInfo($class->implements[$key]);

unset($class->implements[$key]);
}
}
2 changes: 1 addition & 1 deletion rules/Removing/Rector/FuncCall/RemoveFuncCallArgRector.php
Expand Up @@ -69,7 +69,7 @@ public function refactor(Node $node): ?Node
continue;
}

$this->nodeRemover->removeArg($node, $position);
unset($node->args[$position]);
$hasChanged = true;
}
}
Expand Down
3 changes: 3 additions & 0 deletions rules/Removing/ValueObject/RemoveFuncCall.php
Expand Up @@ -4,6 +4,8 @@

namespace Rector\Removing\ValueObject;

use Rector\Core\Validation\RectorAssert;

final class RemoveFuncCall
{
/**
Expand All @@ -13,6 +15,7 @@ public function __construct(
private readonly string $funcCall,
private readonly array $argumentPositionAndValues = []
) {
RectorAssert::functionName($funcCall);
}

public function getFuncCall(): string
Expand Down
3 changes: 3 additions & 0 deletions rules/Removing/ValueObject/RemoveFuncCallArg.php
Expand Up @@ -4,12 +4,15 @@

namespace Rector\Removing\ValueObject;

use Rector\Core\Validation\RectorAssert;

final class RemoveFuncCallArg
{
public function __construct(
private readonly string $function,
private readonly int $argumentPosition
) {
RectorAssert::functionName($function);
}

public function getFunction(): string
Expand Down
2 changes: 1 addition & 1 deletion rules/Transform/Rector/Class_/MergeInterfacesRector.php
Expand Up @@ -109,7 +109,7 @@ private function makeImplementsUnique(Class_ $class): void
foreach ($implements as $key => $name) {
$fqnName = $this->getName($name);
if (in_array($fqnName, $alreadyAddedNames, true)) {
$this->nodeRemover->removeImplements($class, $key);
unset($class->implements[$key]);
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Rector/AbstractRector.php
Expand Up @@ -75,6 +75,9 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn

protected BetterNodeFinder $betterNodeFinder;

/**
* @deprecated Use service directly or return changes nodes
*/
protected NodeRemover $nodeRemover;

protected NodeComparator $nodeComparator;
Expand Down

0 comments on commit 86682e4

Please sign in to comment.