Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
Go to file
2018-12-09 15:26:26 +01:00
bin add XdebugHandler 2018-11-06 23:12:02 +01:00
config/level Fix doctrine rule file name 2018-12-07 11:46:01 +01:00
docs update docs 2018-12-06 01:13:36 +01:00
examples drop too long examples 2018-12-04 21:26:44 +01:00
packages add mixed and variadic cases to *ScalarTypehintRector 2018-12-09 15:26:26 +01:00
src add trait in child class support to ScalarTypehintRector 2018-12-08 21:59:56 +01:00
tests move FilesToReprtingCollector to new cycle in RectorApplication 2018-12-08 15:33:38 +01:00
.coveralls.yml travis: add coverage 2018-10-28 18:47:21 +01:00
.gitignore gitignore: add create-rector.yml 2018-10-15 08:21:55 +08:00
.travis.yml [PHP] Add *ScalarTypehintRector + *TypeInfo 2018-12-01 15:55:46 +01:00
CODE_OF_CONDUCT.md Use HTTPS instead of HTTP 2018-02-14 07:23:09 -02:00
composer.json remove YamlRector 2018-12-06 01:13:36 +01:00
create-rector.yml.dist [Doctrine] Make ReplaceParentRepositoryCallsByRepositoryPropertyRector 2018-10-28 17:50:10 +01:00
ecs-after-rector.yml decouple TemplateVariablesFactory 2018-10-23 20:42:54 +02:00
ecs.yml move FilesToReprtingCollector to new cycle in RectorApplication 2018-12-08 15:33:38 +01:00
LICENSE Update LICENSE year forever 2018-01-02 20:27:07 -02:00
phpstan.neon ErrorAndDiffCollector cleanup 2018-12-08 15:41:55 +01:00
phpunit.xml [CodeQuality] Move coupled location to rest of Rector in standalone package 2018-10-17 19:47:09 +02:00
README.md docs: update How to create own Rector tutorial 2018-11-11 14:09:58 +01:00

Rector - Upgrade your Legacy App to Modern Codebase

Rector is a reconstructor tool - it does instant upgrades and instant refactoring of your code. I mean, why do it manually if 80 % can Rector handle for you?

Build Status Coverage Status Downloads

Rector-showcase

Rector instantly upgrades PHP & YAML code of your application, with focus on open-source projects:



Rector can:

  • Rename classes, methods and properties
  • Rename partial namespace
  • Rename pseudo-namespace to namespace
  • Add, replace or remove arguments
  • Add arguments or return typehint
  • Change visibility of constant, property or method
  • And much more...

...look at overview of all available Rectors with before/after diffs and configuration examples. You can use them to build your own sets.

Install

composer require rector/rector --dev

Do you have conflicts on composer require?

Install prefixed version with isolated dependencies.

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_paths:
        - 'vendor/squizlabs/php_codesniffer/autoload.php'
        - 'vendor/project-without-composer'

You can also exclude files or directories (with regex or fnmatch):

# rector.yml
parameters:
    exclude_paths:
        - '*/src/*/Tests/*'

Running Rector

A. Prepared Sets

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

vendor/bin/rector levels

Let's say you pick symfony40 level and you want to upgrade your /src directory:

# show known changes in Symfony 4.0
vendor/bin/rector process src --level symfony40 --dry-run
# apply
vendor/bin/rector process src --level symfony40

Tip: To process just specific subdirectories, you can use fnmatch pattern:

vendor/bin/rector process "src/Symfony/Component/*/Tests" --level phpunit60 --dry-run

B. Custom Sets

  1. Create rector.yml with desired Rectors:

    services:
        Rector\Rector\Architecture\DependencyInjection\AnnotatedPropertyInjectToConstructorInjectionRector:
            $annotation: "inject"
    
  2. Run on your /src directory:

    vendor/bin/rector process src --dry-run
    # apply
    vendor/bin/rector process src
    

How to Apply Coding Standards?

AST that Rector uses doesn't deal with coding standards very well, so it's better to let coding standard tools do that. Your project doesn't have one? Rector ships with EasyCodingStandard set that covers namespaces import, 1 empty line between class elements etc.

Just use --with-style option to handle these basic cases:

vendor/bin/rector process src --with-style

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.