driftingly/rector-laravel
Rector extension for Laravel that applies automated refactors and upgrade rules based on your composer.json or selected Laravel version sets. Includes rules for core Laravel and first‑party packages like Cashier and Livewire.
LaravelSetList::LARAVEL_CODE_QUALITY, LaravelLevelSetList::UP_TO_LARAVEL_130), allowing granular adoption. This modularity enables incremental migration (e.g., apply only Eloquent magic method refactors first).composer.json to auto-select rules based on current Laravel version, reducing manual configuration overhead.composer require --dev driftingly/rector-laravel) and minimal config (e.g., LaravelSetProvider or manual set selection).LARAVEL_FACTORIES improve IDE autocompletion, while LARAVEL_TYPE_DECLARATIONS enhances static analysis (e.g., PHPStan).UP_TO_LARAVEL_130 includes all prior sets), enabling safe upgrades.LARAVEL_STATIC_TO_INJECTION) may conflict with existing DI patterns. Mitigation: Run in dry mode (--dry-run) first.RemoveDumpDataDeadCodeRector) may remove legitimate debug code. Mitigation: Exclude files/directories via Rector’s --exclude-paths.--parallel) and cache (--cache).RouteActionCallableRector) require manual configuration. Mitigation: Document edge cases in the Rector config.UP_TO_LARAVEL_130) or incrementally (e.g., one major version per release)?LARAVEL_CODE_QUALITY, LARAVEL_STATIC_TO_INJECTION) align with our team’s coding standards?rector/rector) or custom rules?composer make:rule for project-specific refactors.rector process in dry mode (--dry-run) to preview changes.LaravelSetProvider vs. manual sets.LARAVEL_COLLECTION, LARAVEL_TYPE_DECLARATIONS).UP_TO_LARAVEL_130).LARAVEL_STATIC_TO_INJECTION).LaravelLevelSetList for target versions).composer.json.| Priority | Rule Set/Type | When to Apply | Dependencies |
|---|---|---|---|
| High | Version Upgrade Sets | Before major Laravel version upgrades | composer.json Laravel version |
| Medium | Code Quality (LARAVEL_CODE_QUALITY) |
Early in migration | None |
| Medium | Type Declarations | Post-refactor for static analysis | PHP 8.0+ |
| Low | Opinionated (DI, Factories) | Last (requires manual review) | Stable codebase |
| Low | Configurable Rules | As needed (e.g., RemoveDumpDataRector) |
Custom config |
rector-laravel for breaking changes (e.g., new Laravel versions).rector.php.--verbose for detailed logs.rector:diff to compare before/after changes.composer make:rule).--parallel to speed up refactoring.--cache to avoid reprocessing unchanged files.vendor/, node_modules/ via --exclude-paths.RECTOR_MIGRATION.md with rules applied and rationale.| Risk | Impact | Mitigation Strategy |
|---|---|---|
| Broken Builds | CI/CD pipeline failures | Run in dry mode; use --stop-on-failure. |
| Logic Errors | Refactored code behaves incorrectly | Test critical paths; use Git bisect. |
| Configuration Errors | Wrong rules applied | Validate rector.php via rector:config:validate. |
| Performance Degradation | Slow refactoring | Use --parallel; exclude large files. |
| Merge Conflicts | Rule changes conflict with PRs | Coordinate refactors with feature development. |
How can I help you explore Laravel packages today?