hihaho / rector-rules
Hihaho Rector rules for auto-fixing code conventions
Requires
- php: ^8.3
- rector/rector: ^2.6.0
- symplify/rule-doc-generator-contracts: ^11.2
Requires (Dev)
- laravel/boost: ^2.4
- laravel/pao: ^1.1
- laravel/pint: ^1.29
- mrpunyapal/rector-pest: ^0.2.15
- nikic/php-parser: ^5.4
- nunomaduro/collision: ^8.9
- orchestra/testbench: ^10.11||^11.0
- pestphp/pest: ^4.4
- pestphp/pest-plugin-arch: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^12.0
- rector/extension-installer: ^0.11.2||^1.0
- sandermuller/boost-skills: ^2.4
- sandermuller/package-boost-laravel: ^1.0
- spaze/phpstan-disallowed-calls: ^4.10
- symplify/phpstan-extensions: ^12.0
- tomasvotruba/cognitive-complexity: ^1.0
- tomasvotruba/type-coverage: ^2.0
Suggests
- illuminate/support: Used by AssertDatabaseTableToModelClassRector to resolve table names; always present in the Laravel projects this package targets
- rector/extension-installer: Auto-imports this package's config/config.php, so the suffix rules propagate renames when registered directly via withRules() instead of through HihahoSetList::NAMING
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.0
- 0.22.0
- 0.21.0
- 0.20.0
- 0.19.0
- 0.18.0
- 0.17.0
- 0.16.1
- 0.16.0
- 0.15.1
- 0.15.0
- 0.14.0
- 0.13.0
- 0.12.1
- 0.12.0
- 0.11.2
- 0.11.1
- 0.11.0
- 0.10.0
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-docs/nullsafe-receiver-readme
- dev-fix/nullsafe-receiver-scope
- dev-ci/refresh-analysis-caches
- dev-feature/test-field-string-to-constant-rector
- dev-perf/directory-context-memo
This package is auto-updated.
Last update: 2026-11-09 19:23:14 UTC
README
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]);
Installation
composer require hihaho/rector-rules --dev
Requires PHP ^8.3 and Rector ^2.6, and is tested against Laravel 12 and 13.
Usage
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-run
The 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.
Documentation
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
For the static-analysis counterparts, the rules that report but don't rewrite, see
hihaho/phpstan-rules.
Covered by upstream Rector
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])
Testing
composer test
Runs 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.
Changelog
See CHANGELOG.md.
Contributing
Pull requests and issues are welcome. CONTRIBUTING.md covers the local setup, the fixture format, and what CI checks.
Security
Please report security issues privately. SECURITY.md explains how.
Credits
License
MIT. See LICENSE.