A small introduction to Rector 0.19.7 - released during Laracon :)
It requires PHP 7.2 as the lowest version to run. 8.0 and 8.1 to test all the features demoed on the stage.
Fork this repository, clone locally and then install dependencies:
composer update
-
Upgrade PHP
- based on
composer.json
- go one version at a time
- control version in the
withPhpSets()
- promoted properties
- readonly classes
- based on
-
Type coverage
- Add return types
- Add property types based on constructor
- Show
withTypeCoverageLevel()
(coming soon)
-
Dead code removal
- Remove unused properties
- Show
withDeadCodeLevel()
(coming soon)
-
Create a custom Rector rule
- Create a rule
- Hook into a
FuncCall
node - Rename the function
-
Make use of Laravel extension package
composer require driftingly/rector-laravel --dev
- Bonus: Laravel types
- Clone laravel framework and run type coverage level there :)
- Laravel package for Rector: https://github.com/driftingly/rector-laravel/
- Rector book to learn fast: https://leanpub.com/rector-the-power-of-automated-refactoring (updated 2024-02 as well)
- Laravel package for Rector maintainer - https://twitter.com/driftingly
- Peter - active and relentless Rector rules contributor - https://twitter.com/slyfirefox