Skip to content

Creating a Rector

Michiel Roos edited this page Feb 10, 2020 · 4 revisions

There is an explanation of how the basics work over in the Rector Parent repository.

Here we'll show common patterns used in creating the TYPO3 rectors.

Setting values

You can not just assign string values or booleans to the methods you create:

$firstArgument->value = 'info';
$firstArgument->value = true;

Instead, you need to do:

$firstArgument->value = new Node\Scalar\String_('info');
$firstArgument->value = $this->createTrue();

Adding a line before or after the node

You can add a line before or after the current node by using:

$this->addNodeBeforeNode($newNode, $node);

$this->addNodeAfterNode($newNode, $node);

Adding a blank line

Adding a blank line can be done using a \PhpParser\Node\Stmt\Nop instance:

use PhpParser\Node\Stmt\Nop;

$this->addNodeBeforeNode(new Nop(), $node);

$this->addNodeAfterNode(new Nop(), $node);
Clone this wiki locally