Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Rector P Laravel Package

andersundsehr/rector-p

Run Rector on large legacy projects file by file instead of all at once. rector-p asks you before applying changes to each file, remembers files with no changes, and supports paths, chunks, and starting over.

View on GitHub
Deep Wiki
Context7

rector-p is a partial execution wrapper for Rector that makes modernizing large legacy PHP projects manageable. Instead of refactoring an entire codebase in one risky pass, it walks through files individually and prompts you to apply changes file by file, giving you full control over every diff.

It remembers which files produced no changes, so subsequent runs skip them automatically, and supports path arguments to target specific directories or files.

  • Interactive per-file review – approve or reject each proposed change
  • Resume-friendly – tracks unchanged files to avoid re-processing
  • Targeted runs – pass directories or individual files as arguments
  • Chunked execution – process a fraction of files via --chunk=1/2
  • Custom config – point to any rector.php with --config
Frequently asked questions about Rector P
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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo