README: decouple own rector tutorial

This commit is contained in:
TomasVotruba 2017-11-18 16:19:47 +01:00
parent 0fe32fc2d8
commit 61318ef838
2 changed files with 44 additions and 49 deletions

View File

@ -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)

View 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: