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 Rules

Rector Rules Laravel Package

ergebnis/rector-rules

Custom Rector rules from Ergebnis to standardize and modernize PHP code. Includes sorting associative arrays and match arms, converting Faker generator property fetches to method calls, and fixing namespaced symbol references. Install via Composer for dev.

View on GitHub
Deep Wiki
Context7

👓 Provides a composer package with rules for rector/rector.

Frequently asked questions about Rector Rules
How do I install ergebnis/rector-rules for Laravel projects?
Run `composer require --dev ergebnis/rector-rules` in your Laravel project. The package is designed as a dev-dependency and won’t affect production. Ensure you’re using Rector 0.14+ for full compatibility.
Which Laravel versions does this package support?
This package works with any Laravel version but is most useful for projects using PHPUnit 9+ or Pest 2+. The rules focus on modernizing PHP code and test syntax, so they’re compatible with Laravel 8.x, 9.x, and 10.x.
Can I use this to migrate Laravel test annotations like @test to #[Test]?
Yes, the `ReplaceTestAttributeWithTestPrefixRector` rule automates this migration for PHPUnit 9+ test suites. It’s particularly useful for Laravel projects upgrading PHPUnit or adopting Pest 2+. Configure it in your `rector.php` file.
Will these rules break existing Laravel code?
No, the rules are non-breaking and structural. For example, sorting associative arrays or converting Faker property fetches to method calls won’t alter logic. Always test migrations in a staging environment or CI pipeline before merging.
How do I configure the rules for Laravel’s test directories?
Update your `rector.php` to include the rule and specify test directories. Example: `$config->rule(ReplaceTestAttributeWithTestPrefixRector::class)->setPaths([__DIR__.'/tests']);`. Exclude legacy tests using `.rectorignore`.
Does this package work with Pest Framework in Laravel?
The package primarily targets PHPUnit, but you can disable the rule for Pest files. Pest 2+ uses `it()` and `test()` syntax, so avoid running the rule on `tests/Pest.php` files. Use Pest’s native migration tools if needed.
How do I handle custom Laravel test annotations like @uses or @runInSeparateProcess?
The default rule focuses on standard PHPUnit attributes. To handle custom annotations, extend the rule or exclude them via `.rectorignore`. Example: `tests/Unit/*/CustomAnnotationsTest.php`.
Can I run these rules in CI/CD for Laravel projects?
Yes, add the rule to your CI pipeline as a pre-test step. Example GitHub Actions step: `composer rector -- --dir=tests`. Cache results to speed up large test suites. Fail builds on unmigrated attributes or log warnings for gradual adoption.
Are there alternatives to ergebnis/rector-rules for Laravel?
For test attribute migration, Pest provides its own tools. For general code modernization, consider `rector/rector` with its built-in rules or `nunomaduro/collision` for test-specific fixes. This package offers Laravel-specific optimizations like namespaced symbol fixes.
How do I test that migrated tests (e.g., @test → #[Test]) behave identically?
Run parallel test execution with PHPUnit’s `--parallel` flag to validate behavior. Compare test coverage reports before/after migration. For Pest, use its built-in migration validation tools if applicable.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4