Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
Go to file
Tomas Votruba 174fd84aaf wip 2018-04-02 12:14:46 +02:00
bin update bin/rector to Symplify 4 2018-04-02 11:59:21 +02:00
config/level [PHPUnit] Add AssertNotOperatorRector 2018-03-25 07:00:32 -03:00
docs docs: fix location 2018-03-06 21:32:37 +01:00
packages wip 2018-04-02 12:14:46 +02:00
src use DefinitionCollector as non-static class 2018-04-02 11:59:21 +02:00
tests wip 2018-04-02 12:14:46 +02:00
.coveralls.yml init meta files 2017-07-15 19:12:04 +02:00
.gitignore add rector.yml 2018-01-06 17:06:24 +01:00
.travis.yml travis: add Rector test run on itself 2018-03-03 21:06:27 +01:00
CODE_OF_CONDUCT.md Use HTTPS instead of HTTP 2018-02-14 07:23:09 -02:00
LICENSE Update LICENSE year forever 2018-01-02 20:27:07 -02:00
README.md README: improve conflicts section 2018-04-02 12:13:54 +02:00
composer.json bump to ECS 4 2018-04-02 11:59:21 +02:00
easy-coding-standard.yml ecs: allow static for now 2018-04-02 11:59:21 +02:00
ecs-after-rector.yml bump to ECS 4 2018-04-02 11:59:21 +02:00
phpstan.neon Ignore BuilderFactory PHPStan errors 2018-04-02 06:03:06 -03:00
phpunit.dist.xml wip 2018-04-02 12:14:46 +02:00
phpunit.xml phpunit: fix required attributes 2018-02-23 11:26:18 +01:00

README.md

Rector - Upgrade your Legacy App to Modern Codebase

Rector is under development phase in 2018, to figure out the best way to use it in applications, polish API of Rector classes and get feedback from community. Please consider this while using it and report issues or post ideas you'll come up with while using. Thank you!

When you're gonna move from manual work to instant upgrades?

Build Status Coverage Status

Rector-showcase

Rector upgrades your application for you, with focus on open-source projects:

Rector can:

Install

composer require --dev rector/rector:'dev-master'

Do you Have Conflicts?

Since Rector uses project's autoload to analyze type of elements, it cannot be installed as project in standalone directory but needs to be added as dependency. Here bamarni/composer-bin-plugin becomes useful.

In case you have conflicts with different nikic/php-parser version, e.g. while using PHPStan, you can:

Extra Autoloading

Rector relies on project and autoloading of its classes. To specify own autoload file, use --autoload-file option:

vendor/bin/rector process ../project --autoload-file ../project/vendor/autoload.php

How to Reconstruct your Code

A. Prepared Sets

Featured open-source projects have prepared sets. You'll find them in /config/level.

Do you need to upgrade to Symfony 4.0, for example?

  1. Run rector on your /src directory:

    vendor/bin/rector process src --level symfony40
    

    Which is a shortcut for using complete path with --config option:

    vendor/bin/rector process src --config vendor/rector/rector/src/config/level/symfony/symfony40.yml
    

    You can also use your own config file:

    vendor/bin/rector process src --config your-own-config.yml
    
  2. Do you want to see the preview of changes first?

    Use the --dry-run option:

    vendor/bin/rector process src --level symfony33 --dry-run
    
  3. What levels are on the board?

    vendor/bin/rector levels
    

B. Custom Sets

  1. Create rector.yml with desired Rectors:

    services:
        Rector\Rector\Contrib\Nette\Application\InjectPropertyRector: ~
    
  2. Try Rector on your /src directory:

    vendor/bin/rector process src --dry-run
    
  3. Apply the changes if you like them:

    vendor/bin/rector process src
    

Configure Rectors for your Case

You don't have to always write PHP code. Many projects change only classes or method names, so it would be too much work for a simple task.

Coding Standards are Outsourced

This package has no intention in formatting your code, as coding standard tools handle this much better. We prefer EasyCodingStandard with Rector's prepared set:

# install
composer require --dev symplify/easy-coding-standard

# 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

More Detailed Documentation

How to Contribute

Just follow 3 rules:

  • 1 feature per pull-request

  • New feature needs tests

  • Tests, coding standards and PHPStan checks must pass:

    composer complete-check
    

    Don you need to fix coding standards? Run:

    composer fix-cs
    

We would be happy to merge your feature then.