Laravel conventions slip in ways a linter can only report: a table string where a model class belongs, a relation referenced as a magic string. The comment lands in review, and the fix waits for someone to do it by hand. These Rector rules do the rewrite instead, enforcing the Hihaho Development Guidelines as an automated pass.
-$this->assertDatabaseHas('users', ['email' => $email]);
+$this->assertDatabaseHas(\App\Models\User::class, ['email' => $email]);composer require hihaho/rector-rules --devRequires PHP ^8.3 and Rector ^2.6, and is tested against Laravel 12 and 13.
Enable the sets you want in rector.php:
use Hihaho\RectorRules\Set\HihahoSetList;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withPaths([__DIR__ . '/app', __DIR__ . '/database', __DIR__ . '/routes', __DIR__ . '/tests'])
->withSets([
HihahoSetList::ALL, // or pick per set: CODE_QUALITY, ELOQUENT, NAMING, ROUTING, MIGRATIONS, IMPORTS, TESTING
]);Then dry-run before you apply:
vendor/bin/rector process --dry-runThe routing rules only touch files under a routes/ directory and the migration rules
only files under a migrations/ directory, so withPaths() has to reach them.
Read the full documentation at hihaho.github.io/rector-rules.
Getting started
- Why hihaho/rector-rules?: what the rules rewrite, what they refuse to guess at, and when another tool fits better
- Installation: requirements, enabling a set, and the paths the location-gated sets need
- Getting started: one dry run, reading the diff, and keeping the codebase clean in CI
Rule sets
- Code quality: named flag arguments, dropped default arguments,
config()->set(), nullsafe removal - Eloquent:
#[CollectedBy]and#[ObservedBy]conversions, nested eager loading, relation constants - Naming: the suffix each base class implies, and the classes left alone
- Routing: route-path normalization and fluent route groups
- Migrations: INSTANT DDL, self-contained migrations, and the opt-in flag-column conversion
- Imports: aliasing the imports whose short names collide
- Testing: table strings as model classes, and
assertModelExists()
Opt-in rules. Each sits outside every set and is a no-op until registered by FQN.
- Named arguments from a manifest: the manifest schema, and the cache trap that hides a fresh one
- Middleware strings to classes: the behaviour-safe aliases, and the
throttlecaveat - Test payload field names: the internal/public asymmetry and its config contract
- Named arguments on long calls: naming first-party and vendor calls past a threshold, and the magic methods it never touches
- One argument per line: wrapping calls with many arguments, and the Pint settings it needs
- Facades to helper functions: which facades map to which helper, and the facade-only methods it leaves alone
For the static-analysis counterparts, the rules that report but don't rewrite, see
hihaho/phpstan-rules.
Some rules in hihaho/phpstan-rules have no counterpart here, because the fix already
ships upstream. Enable the upstream set.
| PHPStan rule | Upstream set | Notes |
|---|---|---|
onlyAllowFacadeAliasInBlade |
LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES |
Rewrites use Route; to use Illuminate\Support\Facades\Route;, and its siblings |
use RectorLaravel\Set\LaravelSetList; // driftingly/rector-laravel
->withSets([LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES])composer testRuns the full Pest suite. composer qa runs the other three CI gates in one go: Pint,
Rector and PHPStan. It does not run the tests, so run both before pushing.
See CHANGELOG.md.
Pull requests and issues are welcome. CONTRIBUTING.md covers the local setup, the fixture format, and what CI checks.
Please report security issues privately. SECURITY.md explains how.
MIT. See LICENSE.