2017-07-15 19:20:20 +02:00
|
|
|
# Rector - Reconstruct your Legacy Code to Modern Codebase
|
|
|
|
|
|
|
|
[![Build Status](https://img.shields.io/travis/TomasVotruba/Rector/master.svg?style=flat-square)](https://travis-ci.org/TomasVotruba/Rector)
|
|
|
|
[![Coverage Status](https://img.shields.io/coveralls/TomasVotruba/Rector/master.svg?style=flat-square)](https://coveralls.io/github/TomasVotruba/Rector?branch=master)
|
|
|
|
|
2017-09-06 19:37:07 +02:00
|
|
|
This tool will **upgrade your application** for you.
|
2017-07-15 19:20:20 +02:00
|
|
|
|
|
|
|
## All Reconstructors
|
|
|
|
|
2017-09-09 20:44:44 +02:00
|
|
|
At the moment these packages are supported:
|
2017-08-12 13:43:13 +02:00
|
|
|
|
2017-09-09 20:44:44 +02:00
|
|
|
- [Nette](/src/Rector/Contrib/Nette)
|
|
|
|
- [Symfony](/src/Rector/Contrib/Symfony)
|
|
|
|
- [PHPUnit](/src/Rector/Contrib/PHPUnit)
|
|
|
|
- [PHP_CodeSniffer](/src/Rector/Contrib/PHP_CodeSniffer)
|
2017-08-20 17:40:19 +02:00
|
|
|
|
2017-07-15 19:20:20 +02:00
|
|
|
|
|
|
|
## Install
|
|
|
|
|
|
|
|
```bash
|
|
|
|
composer require rector/rector --dev
|
|
|
|
```
|
|
|
|
|
2017-08-21 12:12:51 +02:00
|
|
|
## Use (WIP)
|
2017-07-15 19:20:20 +02:00
|
|
|
|
|
|
|
```bash
|
2017-09-09 20:44:44 +02:00
|
|
|
vendor/bin/rector reconstruct src --level=nette24
|
|
|
|
vendor/bin/rector reconstruct src --level=symfony40
|
2017-07-15 19:20:20 +02:00
|
|
|
```
|
|
|
|
|
2017-08-21 12:12:51 +02:00
|
|
|
|
2017-09-09 20:44:44 +02:00
|
|
|
### 6 Steps to Add New Rector
|
2017-08-21 12:12:51 +02:00
|
|
|
|
|
|
|
Just extend `Rector\Rector\AbstractRector`.
|
2017-09-09 20:44:44 +02:00
|
|
|
It will prepare **2 methods** processing the node.
|
2017-08-21 12:12:51 +02:00
|
|
|
|
|
|
|
```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
|
|
|
|
|
2017-09-09 20:44:44 +02:00
|
|
|
4. Add to specific level, e.g. [`/src/config/level/nette/nette24.yml`](/src/config/level/nette/nette24.yml)
|
|
|
|
|
|
|
|
5. Submit PR
|
2017-08-21 12:12:51 +02:00
|
|
|
|
2017-09-15 00:12:30 +02:00
|
|
|
6. :+1:
|
2017-08-21 12:12:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-15 19:20:20 +02:00
|
|
|
### How to Contribute
|
|
|
|
|
|
|
|
Just follow 3 rules:
|
|
|
|
|
|
|
|
- **1 feature per pull-request**
|
2017-08-21 12:12:51 +02:00
|
|
|
- **New feature needs tests**
|
2017-07-15 19:20:20 +02:00
|
|
|
- Tests, coding standard and PHPStan **checks must pass**
|
|
|
|
|
|
|
|
```bash
|
|
|
|
composer all
|
|
|
|
```
|
|
|
|
|
2017-08-21 12:12:51 +02:00
|
|
|
Don you need to fix coding standards? Run:
|
2017-07-15 19:20:20 +02:00
|
|
|
|
|
|
|
```bash
|
2017-08-21 12:12:51 +02:00
|
|
|
composer fix-cs
|
2017-07-15 19:20:20 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
We would be happy to merge your feature then.
|