LinuxCommandLibrary

rector

Automated PHP code refactoring and upgrades

TLDR

Run rector

$ vendor/bin/rector process [src/]
copy
Dry run
$ vendor/bin/rector process [src/] --dry-run
copy
Specific rule
$ vendor/bin/rector process [src/] --config [rector.php]
copy
Show available rules
$ vendor/bin/rector list-rules
copy
Init configuration
$ vendor/bin/rector init
copy
Clear cache
$ vendor/bin/rector process --clear-cache
copy
Process single file
$ vendor/bin/rector process [src/File.php]
copy

SYNOPSIS

rector command [--dry-run] [--config file] [options] [paths]

DESCRIPTION

Rector performs automated refactoring of PHP codebases, applying rule-based transformations to upgrade syntax, modernize framework usage, and enforce code quality standards. It parses PHP files into an abstract syntax tree and applies configured rules to transform old constructs into their modern equivalents, handling PHP version upgrades (e.g., PHP 7.4 to 8.2) and framework migration (Symfony, Laravel, PHPUnit) automatically.
The --dry-run flag previews all changes without modifying files, making it safe to review transformations before applying them. Rules are organized into sets for common upgrade paths, and custom rules can be written for project-specific refactoring patterns. The tool is typically configured through a rector.php file that specifies which rule sets and individual rules to apply.

PARAMETERS

process

Run refactoring.
init
Create config file.
list-rules
Show available rules.
--dry-run
Show changes without applying.
--config FILE
Configuration file.
--clear-cache
Clear cache.
-v, --verbose
Verbose output.

CONFIGURATION

rector.php

Main configuration file defining rule sets, individual rules, paths to process, and skip patterns. Generated by rector init.

CAVEATS

Review dry-run output carefully. Complex code may need manual fixes. Git commit before running.

HISTORY

Rector was created by Tomas Votruba for automated PHP refactoring. It enables safe, large-scale codebase modernization.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community