Automated PHP Refactoring with Rector

Manual refactoring of a large PHP codebase is slow, error-prone, and expensive. Rector transforms your code automatically using Abstract Syntax Tree (AST) analysis — applying hundreds or thousands of changes in a single auditable pass, with every transformation reviewable before it merges. We use Rector as the engine of our automated refactoring service, and we write custom rules when off-the-shelf sets don't cover your specific patterns.

What is Rector?

Rector is an open-source PHP tool that parses your code into an AST (Abstract Syntax Tree), applies transformation rules, and writes the modified code back. Unlike search-and-replace, it understands types, scopes, and context — so transformations are semantically correct, not just textual.

Rector ships with rule sets for PHP version upgrades, Symfony migrations, Laravel migrations, PHPUnit upgrades, dead code removal, type declarations, and more. When those don't match your codebase, we write custom rules.

How we run Rector refactoring engagements

1. Codebase analysis

We run static analysis tools alongside Rector's dry-run mode to map your codebase: which patterns are present, how many occurrences, what custom rules will be required, and what the risk profile is for each transformation category.

2. Rule set configuration

We configure Rector rule sets appropriate to your target PHP version and framework, then write additional custom rules for patterns specific to your codebase — deprecated internal APIs, bespoke helper functions, proprietary patterns. Custom rules are tested against fixtures before being applied.

3. Batched, auditable runs

We don't apply everything at once. Transformations are batched by rule type and applied as separate pull requests: each diff is reviewable, each change has a clear cause, and the test suite gates every batch. Nothing merges that breaks a test.

4. CI integration

We wire Rector into your CI pipeline so it runs on every pull request, preventing regression to deprecated patterns as your team continues shipping features during the migration.

Common Rector refactoring use cases

  • PHP 7.x → PHP 8.0 / 8.1 / 8.2 / 8.3 syntax upgrades
  • Adding typed properties and return type declarations
  • Symfony 3/4/5 → Symfony 6/7 migrations
  • Replacing deprecated functions and removed APIs
  • Dead code elimination across large codebases
  • Migrating from one ORM to another (e.g. Propel → Doctrine)
  • Replacing custom service location with DI
  • Custom rules for proprietary in-house patterns

What you get at the end

  • A fully upgraded codebase with all transformations applied and tested
  • Custom Rector rules you can reuse and extend
  • Rector integrated into your CI pipeline
  • Documentation of transformations applied and why
  • Handover to your team with guidance on maintaining the Rector config