Plan it 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 Refactoring?
- Improving the code - Preparing for future PHP versions and features - Establishing and/or enforcing new standards - Saving time (and money?) for future features Why?
- 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 nikic/php-parser - 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 configuration - 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
How? I Prepare phase Loop through each classes / traits / interfaces / enums / etc Prepare phase - Build Build a tree of node along with metadata II Rectify phase Apply each rector (aka rule) to each node III Save phase Save diffs to a file “one by one” and go to the next node IV 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? Tailor-made
- 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