Essay Nº 004 — laravel

Rector - automatic refactoring for PHP applications

Patrick Müller · October 26, 2025 · 1 minute read laravel php

Rector is a package that allows you to run automatic refactors on a PHP codebase. You composer require rector/rector and then run ./vendor/bin/rector - the first time it will create a config file and then you can configure it.

This is something I stumbled upon thanks to a youtube video, it looks really useful and I'm surprised I had not heard about it.

Some useful ways to apply this:

  • Modernizing a codebase by setting a set of rules corresponding to a PHP version
  • Removing dead code
  • Introducing type declarations
  • Improving general code quality

A lot of the possible rules can also be run at different levels, that makes it easier to prevent having to review a change of hundreds of files all at once but allows to introduce changes over time by increasing the level.

Here is a blogpost outlining both Rector and how to use it in a GitHub action: https://tighten.com/insights/automated-refactoring-with-rector-php/ Also linked there is a laravel ruleset: https://github.com/driftingly/rector-laravel/tree/main?tab=readme-ov-file