rector/docs/HowToCreateOwnRector.md
2017-11-24 23:58:41 +01:00

857 B

6 Steps to Add New Rector

In case you need a transformation that you didn't find in Dynamic Rectors, you can create your own:

  1. Just extend Rector\Rector\AbstractRector class. It will prepare 2 methods:
public function isCandidate(Node $node): bool
{
}

public function refactor(Node $node): ?Node
{
}
  1. Put it under namespace Rector\Contrib\<set>; namespace
<?php declare(strict_types=1);

namespace Rector\Contrib\Symfony;

use Rector\Rector\AbstractRector;

final class MyRector extends AbstractRector
{
    // ...
}
  1. Add a Test Case - see PHPUnit example

  2. Add to specific level, e.g. /src/config/level/symfony/symfony33.yml

  3. Submit PR

  4. 👍