Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
Go to file
2018-05-29 23:57:29 +02:00
.github add stale-bot config 2018-05-01 23:46:13 +02:00
bin apply on whole Symfony\Bridge 2018-05-29 23:47:03 +02:00
config/level [CodeQuality] Create UnnecessaryTernaryExpressionRector 2018-05-13 14:17:15 -03:00
docs README: add Sylius logo [closes #469] 2018-05-22 17:43:36 +02:00
packages Fixes from PHPStan 2018-05-12 15:15:28 -03:00
src fix cs 2018-05-29 23:56:02 +02:00
tests fix cs 2018-05-19 21:01:44 +02:00
.coveralls.yml init meta files 2017-07-15 19:12:04 +02:00
.gitignore .gitignore: cleanup 2018-05-29 23:57:29 +02:00
.travis.yml travis: add describe command run 2018-04-29 11:16:51 +02:00
CODE_OF_CONDUCT.md Use HTTPS instead of HTTP 2018-02-14 07:23:09 -02:00
composer.json use composer package of php-scoper 2018-05-28 21:06:06 +02:00
easy-coding-standard.yml ecs config: cleanup 2018-05-28 11:17:07 +02:00
ecs-after-rector.yml bump to ECS 4 2018-04-02 11:59:21 +02:00
LICENSE Update LICENSE year forever 2018-01-02 20:27:07 -02:00
phpstan.neon Revert change 2018-05-12 16:57:50 -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 README: add note 2018-05-28 11:33:20 +02:00
scoper.inc.php cleanup tracy from build 2018-05-29 21:50:21 +02:00

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:

...just look at overview of all available Rectors

Install

composer require --dev rector/rector

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. In case you have composer versions conflicts, install prefixed version:

composer require --dev rector/rector-prefixed

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

Or make use of rector.yml config:

# rector.yml
parameters:
    autoload_files:
        - '%kernel.project_dir%/vendor/squizlabs/php_codesniffer/autoload.php'

    autoload_directories:
        - '%kernel.project_dir%/vendor/project-without-composer'

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
    
  4. What does loaded Rectors do?

    vendor/bin/rector describe  --level symfony33
    

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.yml

# fix
vendor/bin/ecs check --config vendor/rector/rector/ecs-after-rector.yml --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.