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

A curated set of custom Rector rules from ergebnis to automate PHP refactoring and style consistency. Includes rules for sorting arrays and match arms, simplifying call arguments, Faker updates, namespace symbol references, and PHPUnit attribute-to-prefix changes.

View on GitHub
Deep Wiki
Context7

Provides rules for rector/rector.

Frequently asked questions about Rector Rules
How do I install ergebnis/rector-rules in a Laravel project?
Run `composer require --dev ergebnis/rector-rules` in your project directory. The package is designed for dev dependencies and integrates directly with Rector, requiring no additional Laravel-specific setup.
Which Laravel versions are compatible with this package?
The package supports Laravel 8.2+ since it requires PHP 8.2+. Ensure your Laravel version aligns with PHP 8.2+ requirements, as the package has no framework-specific dependencies beyond that.
Can I use these rules incrementally instead of applying them all at once?
Yes, enable rules individually in your `rector.php` config. Start with low-risk rules like `RemoveNamedArgumentForSingleParameterRector` and gradually add others. Use `--dry-run` to preview changes before full application.
Will these rules break existing PHPUnit tests in Laravel?
The `ReplaceTestAttributeWithTestPrefixRector` updates test naming conventions (e.g., `#[Test]` to `test*`). Run tests locally after applying this rule to verify compatibility, especially if tests rely on specific naming patterns.
How do I handle false positives with rules like `SortAssociativeArrayByKeyRector`?
False positives may occur if associative arrays have intentional unsorted keys. Disable the rule for specific files or directories in your `rector.php` config, or manually review and exclude problematic cases using Rector’s ignore patterns.
Do these rules work with PestPHP in Laravel?
Yes, the `ReplaceTestAttributeWithTestPrefixRector` aligns with Pest’s `test()` syntax. If you use Pest, enable this rule to standardize test naming across PHPUnit and Pest test suites.
How can I integrate Rector with Laravel’s CI pipeline?
Add a GitHub Actions step to run Rector on PRs or merges. Example: `vendor/bin/rector process --level=all --dry-run`. Fail builds if violations exceed thresholds, ensuring code consistency before deployment.
What if my Laravel project uses custom Faker generators?
The `GeneratorPropertyFetchToMethodCallRector` updates deprecated Faker property fetches to method calls. Test thoroughly if your code relies on custom generators, as this rule may affect dynamic property access patterns.
Are there alternatives to ergebnis/rector-rules for Laravel?
Other Rector rule sets like `rector/rector` or `neomerx/rector-config` exist, but ergebnis/rector-rules focuses on Laravel-specific pain points (e.g., PHPUnit attributes, Faker deprecations). Compare rule sets to match your project’s modernization goals.
How do I configure Rector to skip specific directories in Laravel?
Exclude directories in your `rector.php` config using `$rectorConfig->paths([...])` and `$rectorConfig->skip([...])`. For example, skip vendor files or legacy modules by listing their paths in the skip array.
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope