The same way you're using multiple packages to run your project, Rector works best with company of other tools. Here are some of the most practical ones:
Rector is using php-parser to print the code, so it might add extra space here and there. That's why it's important to have a coding standard tool running.
We recommend Easy Coding Standard, as fast, reliable and its configuration UX is very similar to Rector.
Ideally, first install a coding standard tool, get it to highest level possible and then move on to Rector.
Rector uses PHPStan to understand types. What PHPStan can see, Rector can see too and vice versa. In case you're using a PHPStan baseline and ignore thousands of errors, you're making Rector blind. You can't rename a method call on class of mixed
type.
Add PHPStan to your project, remove baseline and increase level one by one.
To get the best performance out of Rector, you should reach PHPStan level 3-4 without baseline before using.
There 2 more tools that help out with specific sets:
withTypeCoverageLevel()
withDeadCodeLevel()
Last but not least, in 2024 we shipped a home made tool that can help you with various tasks. We use it every project and it's a great help:
It helps with:
composer.json
autoloadThere is also symplify/config-transformer that helps with transforming YAML Symfony configs to PHP. There you can follow up with Symfony rules for Rector to reach config builders.