Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
Go to file
Tomáš Votruba ac98817066
Merge pull request #586 from rectorphp/prefixed-rector-fix
Make build prefixed rector work with .neon files and remove old files
2018-08-21 00:32:43 +02:00
bin fix extra slash 2018-08-21 00:28:20 +02:00
config/level add fluent removal to guzzle50.yml 2018-08-13 11:54:31 +02:00
docs update README 2018-08-15 16:10:47 +02:00
examples move MergeIsCandidateRector to examples 2018-08-15 11:11:15 +02:00
packages revert removed Autowire-Public-Default compiler passes, they were messy 2018-08-21 00:28:20 +02:00
src revert removed Autowire-Public-Default compiler passes, they were messy 2018-08-21 00:28:20 +02:00
tests manual update 2018-08-15 11:11:15 +02:00
.gitignore .gitignore: cleanup 2018-05-29 23:57:29 +02:00
.travis.yml naming 2018-08-21 00:28:20 +02:00
CHANGELOG.md YAML uppercase 2018-07-27 19:44:24 +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 remove so slow coverage check completely 2018-08-16 12:24:42 +02:00
changelog-linker.yml init CHANGELOG.md 2018-07-17 19:50:26 +02:00
composer.json lock to Symplify 4.6.1 2018-08-21 00:28:20 +02:00
ecs-after-rector.yml ecs fix keyword 2018-06-05 20:09:08 +02:00
ecs.yml fix tests - remove .inc 2018-08-14 13:32:40 +02:00
monorepo-builder.yml init monorepo split [closes #425] 2018-07-12 01:17:30 +02:00
phpstan.neon cleanup NodeScopeResolver 2018-08-16 12:15:18 +02:00
phpunit.xml travis: simplify run set 2018-07-25 15:29:42 +02:00
scoper.inc.php cleanup tracy from build 2018-05-29 21:50:21 +02:00

README.md

Rector - Upgrade your Legacy App to Modern Codebase

Rector is a reconstructor tool - it instantly upgrades and refactors your code to a modern one. It 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 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...

...just look at overview of all available Rectors with before/after diffs and configuration examples. It's all you really need to use build your own sets.

Install

composer require rector/rector:@dev --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_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
    

B. Custom Sets

  1. Create rector.yml with desired Rectors:

    services:
        Rector\Nette\Rector\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
    

How to Apply Coding Standards?

Rector uses EasyCodingStandard to improve the code style of changed files, like import namespaces, make 1 empty line between class elements etc.

It's always better to use own project's prepared set, but if you don't have the option yet, 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.