show applied Rectors even on adding/removing nodes

This commit is contained in:
Tomas Votruba 2018-11-09 15:47:23 +01:00
parent b390f1b887
commit 7682a10dd9
3 changed files with 19 additions and 3 deletions

View File

@ -67,11 +67,20 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
*/
public function afterTraverse(array $nodes): array
{
$nodes = $this->nodeAddingCommander->traverseNodes($nodes);
// @todo foreach, array autowire on Required in CommanderInterface[]
if ($this->nodeAddingCommander->isActive()) {
$nodes = $this->nodeAddingCommander->traverseNodes($nodes);
}
$nodes = $this->propertyAddingCommander->traverseNodes($nodes);
if ($this->propertyAddingCommander->isActive()) {
$nodes = $this->propertyAddingCommander->traverseNodes($nodes);
}
return $this->nodeRemovingCommander->traverseNodes($nodes);
if ($this->nodeRemovingCommander->isActive()) {
$nodes = $this->nodeRemovingCommander->traverseNodes($nodes);
}
return $nodes;
}
private function isMatchingNodeType(string $nodeClass): bool

View File

@ -39,11 +39,15 @@ trait NodeAddingTrait
protected function addNodeAfterNode(Expr $node, Node $positionNode): void
{
$this->nodeAddingCommander->addNodeAfterNode($node, $positionNode);
$this->appliedRectorCollector->addRectorClass(static::class);
}
protected function addPropertyToClass(Class_ $classNode, string $propertyType, string $propertyName): void
{
$variableInfo = new VariableInfo($propertyName, $propertyType);
$this->propertyAddingCommander->addPropertyToClass($variableInfo, $classNode);
$this->appliedRectorCollector->addRectorClass(static::class);
}
}

View File

@ -27,5 +27,8 @@ trait NodeRemovingTrait
protected function removeNode(Node $node): void
{
$this->nodeRemovingCommander->addNode($node);
$this->appliedRectorCollector->addRectorClass(static::class);
}
}
q