driftingly/rector-laravel
Community-maintained Rector extension for Laravel. Apply automated refactoring rules to upgrade Laravel (and first-party packages like Cashier/Livewire) via composer-based detection or manual version sets, helping modernize codebases safely and consistently.
PreventRequestForgery middleware renaming), aligning with Laravel’s latest syntax and best practices. This strengthens the package’s role in modernizing Laravel 13+ codebases while maintaining backward compatibility for older versions via version-specific sets.UseSingleQueueableTraitInJobs and fixes for ValidationRuleArrayStringValueToArrayRector demonstrate refined targeting of Laravel’s evolving patterns, reducing false positives in complex scenarios (e.g., closures in rules() methods).getFile() API), future-proofing the package while maintaining AST-based safety.LARAVEL_130 set (PR #485) simplifies adoption for teams upgrading to Laravel 13, with auto-detection via LaravelSetProvider.webmozart/assert ^2, ramsey/composer-install ^4) are non-breaking and align with modern PHP tooling.RenameClassRector, reducing edge-case failures in Livewire-heavy applications.UP_TO_LARAVEL_130 for incremental upgrades.CSRF middleware → PreventRequestForgery (PR #484) may break custom middleware configurations. Risk is limited to Laravel 13+ users.rules() methods, but complex nested rules may still require manual review.UseSingleQueueableTraitInJobs could over-apply in multi-trait scenarios. Test with --dry-run first.--parallel) remains effective for large codebases.Laravel 13 Adoption:
LARAVEL_130 immediately or use UP_TO_LARAVEL_130 for phased upgrades?Rule Safety:
LaravelSetProvider to avoid unintended rule application?Testing Impact:
$table, $fillable) affect serialization/deserialization in APIs?Queueable trait changes (PR #462)?CI/CD Strategy:
PreventRequestForgery) in legacy routes?Long-Term Maintenance:
$casts, $attributes).@onQueue).LARAVEL_CODE_QUALITY for consistent formatting.LARAVEL_TESTING rules for cleaner test syntax.UP_TO_LARAVEL_130 set.Assessment Phase:
use Illuminate\Database\Eloquent\Concerns\HasAttributes).LARAVEL_130 set with --dry-run to preview changes.rector.php to include:
use Rector\Config\RectorConfig;
use Rector\Set\LaravelSetList;
return RectorConfig::create()
->withSets([
LaravelSetList::LARAVEL_130,
LaravelSetList::CODE_QUALITY,
]);
Pilot Phase:
json_encode($model)).YourJob::dispatch()->onQueue('critical')).Full Rollout:
# GitHub Actions example
- name: Run Rector
run: rector process src --set=LARAVEL_130 --level=max --dry-run
$table property) and update tests.UP_TO_LARAVEL_130).livewire/livewire:^4.0 is used.phpunit/phpunit:^10.0 if needed.$table attribute.whereLike()).| Phase | Action | Tools/Commands |
|---|---|---|
| Pre-Migration | Backup, run php artisan test, document critical paths. |
git commit, pest, php artisan tinker |
| Dry Run | Test LARAVEL_130 set without applying changes. |
rector process src --set=LARAVEL_130 --dry-run --parallel |
| Pilot (Models) | Apply Model Attributes rules to a module. | rector process src --set=LARAVEL_130 --level=max --parallel |
| Review | Validate serialization, API responses, and database queries. | php artisan tinker, postman, tinkerwell |
| Pilot (Jobs) | Apply Queueable Trait rules; test job dispatching. | rector process src --set=LARAVEL_130 --exclude=*/Jobs/* --dry-run (then apply |
How can I help you explore Laravel packages today?