mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-04 02:10:51 +00:00
README: decouple own rector tutorial
This commit is contained in:
parent
0fe32fc2d8
commit
61318ef838
55
README.md
55
README.md
|
@ -131,8 +131,8 @@ You can:
|
|||
rectors:
|
||||
Rector\Rector\Dynamic\PropertyNameReplacerRector:
|
||||
# class:
|
||||
# old property: new property
|
||||
'PhpParser\Node\Param':
|
||||
# old property: new property
|
||||
'name': 'var'
|
||||
```
|
||||
|
||||
|
@ -266,66 +266,23 @@ You can:
|
|||
```
|
||||
|
||||
|
||||
### 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**:
|
||||
|
||||
```php
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
}
|
||||
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
}
|
||||
```
|
||||
|
||||
2. Put it under `namespace Rector\Contrib\<set>;` namespace
|
||||
|
||||
```php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Contrib\Symfony;
|
||||
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
||||
final class MyRector extends AbstractRector
|
||||
{
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
3. Add a Test Case
|
||||
|
||||
4. Add to specific level, e.g. [`/src/config/level/symfony/symfony33.yml`](/src/config/level/symfony/symfony33.yml)
|
||||
|
||||
5. Submit PR
|
||||
|
||||
6. :+1:
|
||||
|
||||
|
||||
|
||||
### Coding Standards are Outsourced
|
||||
|
||||
This package has no intention in formatting your code, as **coding standard tools handle this much better**.
|
||||
|
||||
We prefer [EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard) that is already available (no install needed):
|
||||
We prefer [EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard) that is already available:
|
||||
|
||||
```php
|
||||
```bash
|
||||
# check
|
||||
vendor/bin/ecs check --config vendor/rector/rector/ecs-after-rector.neon
|
||||
|
||||
# fix
|
||||
vendor/bin/ecs check --config vendor/rector/rector/ecs-after-rector.neon --fix
|
||||
```
|
||||
|
||||
but you can use any other with [this setup](/ecs-after-rector.neon).
|
||||
|
||||
|
||||
|
||||
### Advanced Operations
|
||||
### More Detailed Documentation
|
||||
|
||||
- [How to Create Own Rector](/docs/HowToCreateOwnRector.md)
|
||||
- [Service Name to Type Provider](/docs/ServiceNameToTypeProvider.md)
|
||||
|
||||
|
||||
|
|
38
docs/HowToCreateOwnRector.md
Normal file
38
docs/HowToCreateOwnRector.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
## 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**:
|
||||
|
||||
```php
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
}
|
||||
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
}
|
||||
```
|
||||
|
||||
2. Put it under `namespace Rector\Contrib\<set>;` namespace
|
||||
|
||||
```php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Contrib\Symfony;
|
||||
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
||||
final class MyRector extends AbstractRector
|
||||
{
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
3. Add a Test Case
|
||||
|
||||
4. Add to specific level, e.g. [`/src/config/level/symfony/symfony33.yml`](/src/config/level/symfony/symfony33.yml)
|
||||
|
||||
5. Submit PR
|
||||
|
||||
6. :+1:
|
Loading…
Reference in New Issue
Block a user