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.
rector/rector, a PHP refactoring tool, making it a natural fit for Laravel/PHP projects requiring automated code modernization. Rector is already widely adopted in Laravel ecosystems (e.g., for PHP 8.x migrations, PSR compliance, or legacy code cleanup).ReplaceTestAttributeWithTestPrefixRector (PHPUnit 9+ compatibility) or Faker\GeneratorPropertyFetchToMethodCallRector (deprecation fixes) directly address maintenance debt, reducing manual effort in PR reviews.composer require --dev ensures zero runtime overhead (dev-only dependency), fitting Laravel’s composer.json workflows.ReferenceNamespacedSymbolsRelativeToNamespacePrefixRector require explicit configuration, reducing accidental refactoring risks. This is critical for Laravel’s namespaced structure (e.g., App\Services\, App\Http\Controllers\).SortAssociativeArrayByKeyRector) may conflict with existing code style tools (PHP-CS-Fixer, Laravel Pint). Validation is needed to avoid unintended side effects.Illuminate\Support\Facades\Route usage).--dry-run) should be tested.ReplaceTestAttributeWithTestPrefixRector break existing tests. A gradual rollout (e.g., per feature branch) is recommended.namespacePrefixes be defined for Laravel’s modular structure (e.g., App\, Modules\)?discoverNamespacePrefixes be enabled by default?SortMatchArmsByConditionalRector misordering) be handled?ReplaceTestAttributeWithTestPrefixRector directly support Laravel’s testing stack (PHPUnit 9+).GeneratorPropertyFetchToMethodCallRector is highly relevant.ReferenceNamespacedSymbolsRelativeToNamespacePrefixRector valuable for consolidating use statements (e.g., use Illuminate\Support\Facades\).SortAssociativeArrayByKeyRector may overlap; order of execution must be defined.RemoveNamedArgumentForSingleParameterRector, Faker updates).App\Services\) before full adoption.rector.php with Laravel-specific prefixes:
return [
'rules' => [
new \Ergebnis\Rector\Rules\Files\ReferenceNamespacedSymbolsRelativeToNamespacePrefixRector(
namespacePrefixes: ['App\\', 'Illuminate\\Support\\Facades\\']
),
new \Ergebnis\Rector\Rules\PHPUnit\ReplaceTestAttributeWithTestPrefixRector(),
],
];
--php-version flag or custom rules to avoid PHP 8.x-only features.ReferenceNamespacedSymbolsRelativeToNamespacePrefixRector may need exclusions for Facade::class usages.resources/views/ from analysis.rector/rector (e.g., Laravel’s phpunit/phpunit vs. Rector’s PHPUnit rules).laravel/framework) to avoid rule misfires.composer require --dev ergebnis/rector-rules.rector.php with safe rules first.--dry-run to preview changes:
vendor/bin/rector process src --dry-run
src/, tests/) to avoid vendor/ or node_modules/.vendor/bin/rector process src tests --config rector.php
ergebnis/rector-rules for new rules (e.g., Laravel 11 compatibility).#[Test] alternatives).rector.php in the team’s style guide.Faker\GeneratorPropertyFetchToMethodCallRector may need retirement as Faker stabilizes.rector.php configurations.node_modules/, storage/).How can I help you explore Laravel packages today?