Rector, time to
01 - One tool to refactor everything
02 - Detect, refactor, test, repeat
03 - Not so live demo
04 - Sky is the limit
05 - Tomorrow is in your hands
- Hard to plan
- Cost a lot of time, money and sweat
- Nobody wants to do it, talk about it and/or even
think about it
- Can introduce errors and BC breaks
- Improving the code
- Preparing for future PHP versions and features
- Establishing and/or enforcing new standards
- Saving time (and money?) for future features
- Most of the time, no or highly opinionated
- Static analysis? Not perfect and not built for
- Unit tests? Used for validation and regression handling
- Human intervention? If you want random errors, yes
Any built-in solution?
- Built in PHP by Tomas Votruba on top of
- Support for PHP >= 5.2 up to 8.2
- Support for Symfony, Laravel, PHPUnit, Nette,
Doctrine and more
- More than 500+ rules
Time to be a corrector
- Fully extensible
- Based on Symfony DIC component for the
- Can be tweaked for almost every project / need
- Need a specific rule? Create your own!
- Can be used in both modern and legacy projects
Wait, there’s more
Loop through each classes
/ traits / interfaces / enums
Prepare phase - Build
Build a tree of node along
Apply each rector (aka
rule) to each node
Save diffs to a ﬁle “one by
one” and go to the next
Once done, a report is generated
- Most cases are built-in but what about yours?
- Processing PHP files is great but what about
YAML? What about JSON files?
- Want to rename __get() to getters?
- Moving from docblocks to custom attributes?
Fair well __get
- What about PHPStan?
- What if Twig templates could be refactored?
- CI and PR integrations?
- Maybe one day, PHP will provide a native tool?
Rector is just the beginning