Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
Go to file
Tomáš Votruba 993a959608
Merge pull request #620 from rectorphp/bump
composer: bump dependencies
2018-09-10 20:59:04 +02:00
bin allow loading --config and --level together [closes #613] 2018-08-30 22:23:51 +02:00
config/level comment 2018-08-29 19:21:13 +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 apply new coding standard rulesets, mostly Slevomat 4.7, cleanup old code 2018-09-06 14:50:23 +02:00
src apply new coding standard rulesets, mostly Slevomat 4.7, cleanup old code 2018-09-06 14:50:23 +02:00
tests allow loading --config and --level together [closes #613] 2018-08-30 22:23:51 +02:00
.gitignore allow loading --config and --level together [closes #613] 2018-08-30 22:23:51 +02:00
.travis.yml travis: add PHP 7.2 build 2018-09-06 14:37:34 +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 README: add fnmatch argument feature 2018-08-30 11:34:41 +02:00
changelog-linker.yml init CHANGELOG.md 2018-07-17 19:50:26 +02:00
composer.json composer: bump dependencies 2018-09-08 11:23:42 +02:00
ecs-after-rector.yml ecs fix keyword 2018-06-05 20:09:08 +02:00
ecs.yml [Symfony] Add ParseFileRector [closes #600] 2018-08-28 18:27:13 +02:00
monorepo-builder.yml init monorepo split [closes #425] 2018-07-12 01:17:30 +02:00
phpstan.neon add expectExceptionMessageRegExp support 2018-08-31 14:45:57 +02:00
phpunit.xml travis: simplify run set 2018-07-25 15:29:42 +02:00
scoper.inc.php remove AbstractRectorTestCase.php from prefixed scope 2018-08-28 12:26:26 +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'

You can also exclude files or directories - use regex or fnmatch:

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

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. To process just specific subdirectories, you can use fnmatch pattern with *:

    vendor/bin/rector process "src/Symfony/Component/*/Tests" --level phpunit60 --dry-run
    
  4. 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.