mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-21 09:42:45 +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
46 lines
1.1 KiB
Markdown
46 lines
1.1 KiB
Markdown
# 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
|
|
|
|
```bash
|
|
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
|
|
|
|
```bash
|
|
vendor/bin/rector init-recipe
|
|
```
|
|
|
|
2. Complete parameters in `rector-recipe.php` to design your new rule
|
|
|
|
3. Run command
|
|
|
|
```bash
|
|
vendor/bin/rector generate
|
|
```
|
|
|
|
That's it :)
|