Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
Go to file
Tomas Votruba bffacb1af7 README: fix install br dev 2018-05-11 00:10:11 +02:00
.github add stale-bot config 2018-05-01 23:46:13 +02:00
bin DescribeCommand - first draft 2018-04-09 00:23:55 +02:00
config/level Merge pull request #458 from rectorphp/action-inject-to-constructor 2018-05-05 16:21:45 +01:00
docs Merge pull request #458 from rectorphp/action-inject-to-constructor 2018-05-05 16:21:45 +01:00
packages fixup stubs 2018-05-10 19:08:17 +02:00
src add default App\Kernel class 2018-05-10 22:02:42 +02:00
tests add default App\Kernel class 2018-05-10 22:02:42 +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 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
LICENSE Update LICENSE year forever 2018-01-02 20:27:07 -02:00
README.md README: fix install br dev 2018-05-11 00:10:11 +02:00
composer.json composer: use stable deps 2018-05-11 00:10:05 +02:00
easy-coding-standard.yml update namespaces 2018-05-10 19:05:41 +02:00
ecs-after-rector.yml bump to ECS 4 2018-04-02 11:59:21 +02:00
phpstan.neon static fix 2018-05-05 13:44:44 +01: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:

...just look at overview of all available Rectors

Install

composer require --dev rector/rector roave/better-reflection:dev-master#f8b3fc6

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

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.