logo

Get the benefits of final classes in Rector

You don't have to commit to final - there's a setting for that

Aaron Saray
Aaron Saray
2026-01-15

Rector is a powerful tool for automated code refactoring and upgrades. Among its many features, it can enforce coding standards and apply fixes across your entire codebase.

One setting I find particularly useful is ->withTreatClassesAsFinal(). When enabled, Rector analyzes your code as if all classes were declared final, even when they're not.

return RectorConfig::configure()
    ->withTreatClassesAsFinal();

There's a whole debate about whether classes should be final by default. I'll sidestep that. But this setting helps Rector in a very useful and specific way.

It tells Rector to assume your classes won't be extended and this lets it make smarter decisions about method visibility and inheritance. You get the stricter analysis without actually committing to final in your code.

Here to help,

Aaron

P.S. Want help configuring Rector or improving other parts of your codebase? Schedule a code review and we'll dig in together.

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.