Introduction

Rector requires PHP 7.2+. It can work with PHP 5.x and 8.x code. It works best with OOP, typed code with separated PHP and template layers.

Install

composer require rector/rector --dev

You can run it from your bin directory:

vendor/bin/rector

First Run

Rector works with rector.php config file. You can create it manually, or Rector handle it for you:

vendor/bin/rector

 No "rector.php" config found. Should we generate it for you? [yes]:
 > yes


 [OK] The config is added now. Re-run command to make Rector do the work!

In rector.php you define paths and what to run on them. Start small, one level at a time, so the first pull request is easy to review:

<?php

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/src',
        __DIR__ . '/tests',
    ])
    ->withTypeCoverageLevel(0);

Each run, raise the level by one. See Levels for how levels work and New Project for the full walkthrough.

To see preview of suggested changed, run process command with --dry-run option:

vendor/bin/rector process --dry-run

To make changes happen, run bare command:

vendor/bin/rector process

All options are listed on the CLI options page.