mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-19 15:45:43 +01:00
* 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
1.1 KiB
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
-
Run Generate command in Interactive Mode
vendor/bin/rector generate --interactive
-
Provide an answer to questions asked by the command
Generate using configuration file
-
Initialize
rector-recipe.php
configvendor/bin/rector init-recipe
-
Complete parameters in
rector-recipe.php
to design your new rule -
Run command
vendor/bin/rector generate
That's it :)