rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.74k stars 687 forks source link

[DX] Allow more granulated return type completion, to separate from closures and makes easier to review #8678

Closed TomasVotruba closed 4 months ago

TomasVotruba commented 5 months ago

We've done similar split in the past, to make type declaration level work in as small steps as possible. This would concert few ReturnType* rules that now handle all functions, method, closure together.

The closure rules should be split of these and have separate rule inside TypeDeclarationLevel

Ref https://x.com/apefm/status/1803148500693102681

TomasVotruba commented 4 months ago

Looking into this.

At the moment we have single AddArrowFunctionReturnTypeRector to handle these cases. I think it makes sense, as in the wild there is hundreds of methods/functions, but much less callbacks/arrow functions. So it's easier to review these cases without granulation.

We can introduce possibly single rule, e.g. ClosureReturnTypeRector to handle such cases. That would keep ClassMethod and Fuction_ rules separated, and easier to add types to closure on separete Rector run :)

samsonasik commented 4 months ago

ClosureReturnTypeRector can be added, and register after other closure return types rules so executed on last

TomasVotruba commented 4 months ago

@samsonasik That's the plan. void and never are the easy ones to pick