rector/rector-laravel
Community Rector extension to automate Laravel upgrades. Adds Laravel and first-party package rules (e.g., Cashier, Livewire), with version-based set providers that detect your composer.json or manual level sets to apply the right refactors for your target Laravel version.
blank()/filled() over empty(), type declarations, collection optimizations) via pre-commit hooks or CI pipelines. Aligns with PSR-12 and Laravel’s evolving best practices.LARAVEL_CODE_QUALITY, LARAVEL_STATIC_TO_INJECTION) to clean up legacy codebases without full rewrites. Prioritize high-impact areas like container bindings or Eloquent magic methods.dd() removal). Integrate with PHPStan or Psalm for type safety post-refactor.assertSee() → assertStringContains()) during Laravel version bumps. Critical for CI/CD pipelines with flaky tests."This tool automates 80% of the manual work in upgrading Laravel—saving 2–4 weeks per major version for a team of 5. For example, migrating from Laravel 8 to 13 typically requires 10–15 hours of manual refactoring per developer; Rector cuts that to under 2 hours with zero risk of human error. It’s like having a senior Laravel dev on call 24/7 to enforce best practices. The MIT license and active community (1.2K stars) make it a low-risk, high-reward investment for technical debt reduction."
ROI Hook:
*"Rector/Laravel lets us treat code upgrades like infrastructure updates—repeatable, auditable, and scalable. Key wins:
--dry-run) lets us preview changes before merging.composer make:rule).Example Workflow:
# Upgrade Laravel 11 → 12 in one command:
rector process src --config=rector.php --set=LaravelLevelSetList::UP_TO_LARAVEL_120
Blockers to Address:
dd() removal). Start with --dry-run.*"Stop manually fixing Laravel deprecations! This tool writes the boring refactoring code for you:
Cache::get() to constructor injection.Model::factory()->create() to UserFactory::new().where() chains with filter() or reject().dd() calls in one command.Pro Tip:
Use LaravelSetList::LARAVEL_CODE_QUALITY to auto-fix common anti-patterns like:
// Before
if (empty($request->input('name'))) { ... }
// After (auto-applied)
if ($request->input('name')->isEmpty()) { ... }
Try It:
composer require --dev driftingly/rector-laravel
rector init --with-config --with-set=LaravelSetList::LARAVEL_TYPE_DECLARATIONS
```"
How can I help you explore Laravel packages today?