Weave Code
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 Laravel Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Seamless Laravel Integration: The package is designed specifically for Laravel, leveraging Rector’s static analysis capabilities to automate codebase upgrades, refactoring, and modernization. It aligns perfectly with Laravel’s evolving syntax, APIs, and best practices (e.g., facades → DI, legacy factories → classes, Eloquent magic methods → Query Builder).
  • Modular Rule Sets: Rules are organized into version-specific (LaravelLevelSetList) and opinionated sets (LaravelSetList), allowing granular adoption. This modularity ensures compatibility with incremental upgrades (e.g., Laravel 12 → 13) without forcing a monolithic refactor.
  • Extensibility: Supports custom rules via composer make:rule, enabling TPMs to tailor the tool to niche use cases (e.g., project-specific naming conventions or legacy patterns).

Integration Feasibility

  • Low Friction: Installation is a one-liner (composer require --dev driftingly/rector-laravel), and configuration is minimal (auto-detection via composer.json or manual set selection). No runtime dependencies or server changes are required.
  • CI/CD Friendly: Rules can be executed in pre-commit hooks, PR checks, or scheduled pipelines (e.g., nightly upgrades). The package includes GitHub Actions workflows for testing, ensuring reliability.
  • Backward Compatibility: Rules are designed to be non-breaking when applied incrementally. For example, UP_TO_LARAVEL_130 includes rules for all prior versions, reducing risk of partial migrations.

Technical Risk

  • Rule Accuracy: False positives/negatives in refactoring (e.g., RouteActionCallableRector misinterpreting controller namespaces) could introduce bugs. Mitigation: Run in dry mode (--dry-run) and review diffs.
  • Dependency Conflicts: Rector itself requires PHP 8.1+, Laravel 9+, and specific Composer versions. Audit compatibility with legacy projects upfront.
  • Stateful Refactors: Some rules (e.g., RemoveModelPropertyFromFactoriesRector) may conflict with existing migrations or custom logic. Test in a staging environment first.
  • Performance: Large codebases may experience slow analysis. Optimize by:
    • Running rules in parallel (--parallel).
    • Excluding irrelevant directories (--exclude-paths).

Key Questions for TPMs

  1. Upgrade Strategy:
    • Are we targeting a single version jump (e.g., 10 → 11) or incremental modernization (e.g., 10 → 11 → 12)?
    • Should we use auto-detection (withComposerBased) or manual sets for finer control?
  2. Rule Prioritization:
    • Which sets align with our technical debt goals (e.g., LARAVEL_CODE_QUALITY vs. LARAVEL_STATIC_TO_INJECTION)?
    • Do we need to customize or disable any rules (e.g., RemoveDumpDataDeadCodeRector in debug environments)?
  3. Validation:
    • How will we verify correctness post-refactor? (Unit tests, manual review, E2E tests?)
    • Should we gate refactors behind feature flags or canary deployments?
  4. Team Adoption:
    • Will developers need training on new patterns (e.g., DI over facades)?
    • How will we handle merge conflicts during collaborative refactoring?

Integration Approach

Stack Fit

  • PHP/Laravel Ecosystem: Native support for Laravel’s core, Cashier, Livewire, and testing tools. Integrates with:
    • Composer: Dependency management and version detection.
    • PHPStan/Psalm: Static analysis tools for pre-refactor validation.
    • Git: Diff tools (git diff) to review changes.
  • Toolchain Compatibility:
    • CI/CD: Works with GitHub Actions, GitLab CI, or Jenkins (example workflows provided).
    • IDE: Supports PHPStorm/VSCode for real-time feedback (via Rector’s --watch mode).
    • Monorepos: Can target specific packages via --paths.

Migration Path

  1. Assessment Phase:
    • Run rector process in dry mode to identify affected files/rules.
    • Audit composer.json for Laravel/package versions to auto-configure sets.
  2. Incremental Rollout:
    • Phase 1: Apply non-breaking rules (e.g., LARAVEL_CODE_QUALITY, LARAVEL_COLLECTION).
    • Phase 2: Tackle API changes (e.g., LARAVEL_STATIC_TO_INJECTION, LARAVEL_ELOQUENT_MAGIC_METHOD).
    • Phase 3: Enforce opinionated rules (e.g., ResponseHelperCallToJsonResponseRector).
  3. Validation:
    • Unit Tests: Ensure critical paths pass.
    • Manual Review: Focus on high-risk areas (e.g., route definitions, factories).
    • Performance Benchmarks: Compare before/after (e.g., query builder vs. magic methods).

Compatibility

  • Laravel Versions: Supports 9.x → latest (as of 2026). Check LaravelLevelSetList for target versions.
  • Custom Code: Rules may fail on:
    • Dynamic code (e.g., eval(), create_function()).
    • Third-party packages with unsupported patterns (e.g., custom facades).
    • Legacy PHP (<8.1) or non-standard PSR compliance.
  • Mitigations:
    • Use --exclude-paths to skip problematic directories.
    • Extend with custom rules for edge cases.

Sequencing

  • Order of Operations:
    1. Backup codebase (Git tag or export).
    2. Run in CI to catch issues early.
    3. Start with low-risk sets (e.g., LARAVEL_ARRAYACCESS_TO_METHOD_CALL).
    4. Gradually increase complexity (e.g., DI refactors last).
    5. Automate in PRs post-validation (e.g., require Rector checks for new code).
  • Anti-Patterns to Avoid:
    • Running all rules at once (risk of cascading failures).
    • Skipping validation for "quick wins" (e.g., dd() removal may hide bugs).

Operational Impact

Maintenance

  • Long-Term Benefits:
    • Reduced Tech Debt: Automates tedious upgrades (e.g., facades → DI, legacy factories).
    • Consistency: Enforces modern Laravel patterns (e.g., blank() over empty()).
    • Future-Proofing: Easier to adopt new Laravel versions with minimal manual work.
  • Ongoing Costs:
    • Rule Updates: Monitor for new Rector/Laravel releases (e.g., Laravel 14 support).
    • Custom Rules: Maintain project-specific rules if created.
    • Deprecation Tracking: Some rules may become obsolete (e.g., Laravel 12 → 13).

Support

  • Troubleshooting:
    • Logs: Rector provides detailed diffs and error messages.
    • Community: Active GitHub issues and Rector Slack/Discord.
    • Debugging: Use --dry-run and --verbose flags.
  • Rollback Plan:
    • Git Revert: If issues arise, revert the commit introducing Rector changes.
    • Configuration: Disable problematic rules in rector.php.
  • Team Skills:
    • Required: Basic PHP/Laravel knowledge to review changes.
    • Recommended: Familiarity with Rector’s CLI and rule sets.

Scaling

  • Performance:
    • Large Codebases: Use --parallel and --exclude-paths to optimize.
    • Distributed Teams: Run Rector in CI to avoid local performance bottlenecks.
  • Parallelization:
    • Rules are idempotent; can be run concurrently across branches.
    • Example: Team A refactors app/Http, Team B refactors app/Models.
  • Infrastructure:
    • No server-side changes needed; runs locally or in CI.
    • For monorepos, use --paths to target specific packages.

Failure Modes

Risk Impact Mitigation
False-positive refactors Broken functionality Review diffs manually; use --dry-run.
Rule conflicts Merge conflicts in CI Sequence rule sets; use feature flags for critical paths.
Performance degradation Slow CI builds Cache Rector results; run in parallel.
Incomplete refactors Legacy code remains Audit with rector process --list-rules to ensure full coverage.
Dependency version mismatches Rector/Laravel incompatibility Pin versions in composer.json
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity