- 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.