rector/README.md

126 lines
2.6 KiB
Markdown
Raw Normal View History

2017-07-15 17:20:20 +00:00
# Rector - Reconstruct your Legacy Code to Modern Codebase
2017-09-21 10:40:27 +00:00
[![Build Status](https://img.shields.io/travis/RectorPHP/Rector/master.svg?style=flat-square)](https://travis-ci.org/RectorPHP/Rector)
[![Coverage Status](https://img.shields.io/coveralls/RectorPHP/Rector/master.svg?style=flat-square)](https://coveralls.io/github/RectorPHP/Rector?branch=master)
2017-07-15 17:20:20 +00:00
2017-09-06 17:37:07 +00:00
This tool will **upgrade your application** for you.
2017-07-15 17:20:20 +00:00
## All Reconstructors
2017-09-09 18:44:44 +00:00
At the moment these packages are supported:
2017-09-09 18:44:44 +00: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 15:40:19 +00:00
2017-07-15 17:20:20 +00:00
## Install
```bash
composer require rector/rector --dev
```
# Install on PHP < 7.1
You must have separated environment with PHP 7.1 (for example in Docker container). When you have it then run following command.
```
composer create-project rector/rector your-path-to-rector
```
When do you have it then you can run all commands like
```
your-path-to-rector/bin/rector process /var/www/old-project --level=nette24
your-path-to-rector/bin/rector process /var/www/another-old-project --level=symfony40
```
2017-09-27 21:58:14 +00:00
## How To Reconstruct your Code?
1. Create `rector.yml` with desired Rectors
```yml
rectors:
- Rector\Rector\Contrib\Nette\Application\InjectPropertyRector
2017-09-27 21:58:14 +00:00
```
2. Run rector on your `/src` directory
2017-07-15 17:20:20 +00:00
```bash
2017-09-27 21:58:14 +00:00
vendor/bin/rector process src
```
3. Check the Git
```
git diff
2017-07-15 17:20:20 +00:00
```
2017-08-21 10:12:51 +00:00
2017-09-09 18:44:44 +00:00
### 6 Steps to Add New Rector
2017-08-21 10:12:51 +00:00
Just extend `Rector\Rector\AbstractRector`.
2017-09-09 18:44:44 +00:00
It will prepare **2 methods** processing the node.
2017-08-21 10:12:51 +00: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 18:44:44 +00: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 10:12:51 +00:00
2017-09-14 22:12:30 +00:00
6. :+1:
2017-08-21 10:12:51 +00:00
2017-09-28 15:15:40 +00:00
### READMEs for Subpackages
- [DeprecationExtractor](/packages/DeprecationExtractor/README.md)
- [NodeTraverserQueue](/packages/NodeTraverserQueue/README.md)
- [NodeTypeResolver](/packages/NodeTypeResolver/README.md)
- [NodeValueResolver](/packages/NodeValueResolver/README.md)
2017-08-21 10:12:51 +00:00
2017-07-15 17:20:20 +00:00
### How to Contribute
Just follow 3 rules:
- **1 feature per pull-request**
2017-08-21 10:12:51 +00:00
- **New feature needs tests**
2017-07-15 17:20:20 +00:00
- Tests, coding standard and PHPStan **checks must pass**
```bash
composer all
```
2017-08-21 10:12:51 +00:00
Don you need to fix coding standards? Run:
2017-07-15 17:20:20 +00:00
```bash
2017-08-21 10:12:51 +00:00
composer fix-cs
2017-07-15 17:20:20 +00:00
```
We would be happy to merge your feature then.