- How does rector-p differ from running Rector directly in a Laravel project?
- Rector-p wraps Rector to process files one-by-one, prompting you to approve or skip changes per file. This is ideal for large Laravel projects where applying all refactoring at once is risky. It also supports chunking (e.g., 1/2) to process portions of the codebase incrementally, unlike Rector’s all-or-nothing execution.
- Can I use rector-p with Laravel-specific Rector rules (e.g., laravel-10 preset)?
- Yes, rector-p fully supports Laravel presets like `laravel-10` or `laravel-90`. Your existing `rector.php` configuration remains unchanged, and rector-p integrates seamlessly with these rules. No additional setup is required beyond `composer req andersundsehr/rector-p`.
- What Laravel versions does rector-p support, and are there any compatibility risks?
- Rector-p supports the same Laravel versions as Rector itself, typically back to Laravel 5.8+. The package doesn’t introduce new risks—always test on a staging environment first, especially for older Laravel versions. The backported PR (10.2.8) doesn’t alter compatibility, so existing workflows remain unaffected.
- How do I run rector-p on specific files or directories in a Laravel project?
- Use the path argument: `rector-p src/Http/Controllers/` to target a directory or `rector-p app/Models/User.php` for a single file. You can also combine paths: `rector-p app/Models/User.php app/Providers/AppServiceProvider.php`. This granularity is perfect for Laravel’s modular structure.
- Is rector-p safe for production? What if I accidentally approve changes?
- Rector-p is designed for non-production use. Always run it in a staging environment or with `--dry-run` first. If you approve changes accidentally, use `--startOver` to reset or revert via Git. For extra safety, pair it with feature flags or PHPUnit tests before deploying to production.
- How does the chunking feature (e.g., --chunk=1/2) work in Laravel projects?
- Chunking splits your Laravel codebase into portions (e.g., 1/2 processes the first half of files). Use it to refactor incrementally, like targeting `src/Http/` first, then `app/Console/` later. This is especially useful for large Laravel apps where full refactoring is overwhelming. Example: `rector-p --chunk=1/3` processes the first third of files.
- Can I automate rector-p in CI/CD pipelines for Laravel projects?
- Yes, use the `--no-interaction` flag to skip prompts: `rector-p --no-interaction`. This is ideal for CI/CD pipelines where manual approvals aren’t feasible. However, always pair it with `--dry-run` in production pipelines to avoid unintended changes. Test thoroughly in staging first.
- What alternatives to rector-p exist for incremental Laravel refactoring?
- Alternatives include Rector’s native `--dry-run` or `--parallel` flags, but they lack rector-p’s interactive approvals and chunking. Tools like `robo` or custom scripts can also automate file-by-file processing, but none offer the same safety net for Laravel projects. Rector-p is uniquely tailored for legacy Laravel codebases.
- How do I resume rector-p after a partial run or interruption?
- Rector-p remembers processed files and skips unchanged ones by default. If you need to restart, use `--startOver` to reset the cache. For interrupted runs, simply re-run the command—it will prompt only for modified files. This is especially useful for long-running Laravel refactoring sessions.
- Does rector-p work with PHPUnit or Pest for testing Laravel refactoring?
- Yes, rector-p integrates with PHPUnit/Pest for validation. Run your test suite after approving changes in rector-p to ensure refactoring doesn’t break functionality. Use feature flags to toggle refactored code during testing. This is a best practice for Laravel projects to catch regressions early.