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.
Strengths:
LARAVEL_CODE_QUALITY, LARAVEL_COLLECTION, LARAVEL_STATIC_TO_INJECTION), allowing targeted application (e.g., only upgrade Eloquent queries without touching Facades).composer.json to auto-select rules for the current Laravel version, reducing configuration overhead for version upgrades.LARAVEL_TYPE_DECLARATIONS) and customizable ones (e.g., RouteActionCallableRector), balancing convenience and flexibility.Gaps:
users table for Laravel Auth). Requires manual or separate tooling (e.g., Laravel Migrations, Doctrine DBAL).--dev, ensuring it doesn’t affect production builds.rector process src) or CI step, with no runtime overhead.LARAVEL_TYPE_DECLARATIONS improve IDE autocompletion and static analysis (e.g., PHPStan, Psalm), but may require IDE resyncing post-rector.RemoveDumpDataDeadCodeRector) may aggressively remove debug code or misinterpret dynamic method calls (e.g., $model->{$method}()).rector process --dry-run) and review diffs. Use --skip to exclude problematic files/directories.LARAVEL_STATIC_TO_INJECTION or LARAVEL_ELOQUENT_MAGIC_METHOD_TO_QUERY_BUILDER may break existing logic if not thoroughly tested.--cache-dir for repeated runs.rector/rector) or PHP versions (<8.1).composer.json and test in isolated environments.LARAVEL_CODE_QUALITY) first, or accept breaking changes for long-term benefits (e.g., LARAVEL_STATIC_TO_INJECTION)?abort() helpers) with modern equivalents.rector process --dry-run on a staging environment to identify affected files/rules.LARAVEL_CODE_QUALITY, LARAVEL_TYPE_DECLARATIONS).LARAVEL_STATIC_TO_INJECTION) in a feature branch.return RectorConfig::configure()
->withSetProviders(LaravelSetProvider::class)
->withComposerBased(laravel: true);
LARAVEL_COLLECTION for performance optimizations).--exclude vendor/) and generated files (e.g., bootstrap/cache/).--skip src/Custom/Logic.php).composer make:rule for project-specific needs (e.g., legacy API wrappers).How can I help you explore Laravel packages today?