logo
podcast Podcast
get help Get Unstuck

How to run just one Rector rule at a time

And why you might want to

Joel Clermont
Joel Clermont
2025-08-05

When working on the revised version of our validation book, I needed to update our tests from PHPUnit 9 to PHPUnit 10.

This involved a handful of mechanical changes, like moving from annotations to attributes, or refactoring data providers to be static.

Rector helps automate this process with their PHPUnit 10 rule set.

But I didn't want to apply everything in this rule set, at least not all at once.

To keep the diffs more manageable to review, I wanted to run just 3 of the 16 rules in that set, and make a git commit for each one.

Thankfully, Rector makes this easy by letting you specify a single rule to run from the command line with the --only option.

It looks like this:

vendor/bin/rector --only="\Rector\PHPUnit\SomeClassNameRector"

The syntax is straightforward, but two important things to note:

  1. The rule class must be fully qualified and surrounded by quotes.
  2. The rule has to be enabled in your rector.php configuration file, or it won't run. It can be part of a larger rule set, but it must be enabled.

I love how Rector not only helps me make large sweeping changes to my project, but also to do it in a controlled and precise way to match my desired workflow.

Here to help,

Joel

P.S. If you've never used Rector, but you'd like some help using it to standardize and modernize your project, get in touch.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.