rector icon indicating copy to clipboard operation
rector copied to clipboard

[dx] add "treat classes as final" option, to enable more advanced level of rules without making every class explicitly final

Open TomasVotruba opened this issue 8 months ago • 4 comments

This should be an optional feature, off by default. When enabled, rules like AddTypeToConstRector should run even on final classes. Devs often want to use more such type coverage features in Rector, but making everything final is way too much work just to try it out.

Let's make upgrades a bit more easier by adding this option 🤗

return RectorConfig::configure()
    ->treatClassesAsFinal()

@samsonasik Could you kick this off?

TomasVotruba avatar Jun 11 '25 11:06 TomasVotruba

I will try

samsonasik avatar Jun 11 '25 11:06 samsonasik

Looking at the rule, it seems we can do: "inline_public" config instead, that's will make less destructive when choose which rule that needs to allow add type on "public/protected" proprerty/const.

I will create 2 PRs alternative for it.

samsonasik avatar Jun 11 '25 11:06 samsonasik

Indeed. I think both options would be valuable👌

TomasVotruba avatar Jun 11 '25 11:06 TomasVotruba

I created 2 alternative PRs:

  • https://github.com/rectorphp/rector-src/pull/6974
  • https://github.com/rectorphp/rector-src/pull/6975

I prefer "alternative 2" option, as this feel less destructive, and more "inline_public" with other typed rules:

  • https://getrector.com/rule-detail/class-property-assign-to-constructor-promotion-rector
  • https://getrector.com/rule-detail/typed-property-from-assigns-rector

samsonasik avatar Jun 11 '25 12:06 samsonasik

Let's close this as implemented 👍

samsonasik avatar Jun 25 '25 10:06 samsonasik

👍

TomasVotruba avatar Jun 25 '25 14:06 TomasVotruba

This issue has been automatically locked because it has been closed for 150 days. Please open a new issue if you have a similar problem.

github-actions[bot] avatar Nov 28 '25 03:11 github-actions[bot]