rector/docs/rector_recipe.md
Krystian Marcisz 94a4bb7777
[DX] Add Interactive Mode to Generate command (#4931)
* Add Interactive Mode to Generate command

* CS Fixer

* Unify names

* Unify names

* Fixes

* Fixes

* Fixes

* Check generated tests against the "special hack for PHPUnit"

* Re-use the same input/output in the Generate Command

* Add test for Interactive Mode of Generate Command

* Rename test file

* Use ::class instead of string

* Create Finder instance where it's used

* Create RectorRecipeInteractiveProvider service

* Create RectorRecipeInteractiveProvider service

* Bring back SymfonyStyle as DI service
2020-12-28 18:00:51 +01:00

1.1 KiB

Generate a new Rector Rule

Creating a new Rector rule means many small steps. You need to create rule file, test file, test fixtures, put it into right category, bla bla bla...

How can we remove repeated work and let us focus only on refactor() method?

What generate Command is Does?

It creates a bare structured Rule. Don't worry, also generates a test case, which is required to contribute.

How to Generate Rector rule?

There are two possibilities to Generate a Rector rule.

Generate using Interactive Mode

Important: using this approach will generate Rector rule with placeholder Code Samples, which should be changed by hand to reflect what the rule does

  1. Run Generate command in Interactive Mode

    vendor/bin/rector generate --interactive
    
  2. Provide an answer to questions asked by the command

Generate using configuration file

  1. Initialize rector-recipe.php config

    vendor/bin/rector init-recipe
    
  2. Complete parameters in rector-recipe.php to design your new rule

  3. Run command

    vendor/bin/rector generate
    

That's it :)