PHPackages                             hihaho/rector-rules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hihaho/rector-rules

ActiveRector-extension[Utility &amp; Helpers](/categories/utility)

hihaho/rector-rules
===================

Hihaho Rector rules for auto-fixing code conventions

0.1.4(1mo ago)14.5k—1.3%[2 PRs](https://github.com/hihaho/rector-rules/pulls)MITPHPPHP ^8.3CI passing

Since Apr 12Pushed 1w ago1 watchersCompare

[ Source](https://github.com/hihaho/rector-rules)[ Packagist](https://packagist.org/packages/hihaho/rector-rules)[ Docs](https://guidelines.hihaho.com)[ RSS](/packages/hihaho-rector-rules/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (4)Dependencies (20)Versions (10)Used By (0)

Hihaho Rector Rules
===================

[](#hihaho-rector-rules)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7c4df9eb37a8484947390ff32c9faecf44c2c9ca851d928aae17dccf0698f358/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68696861686f2f726563746f722d72756c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hihaho/rector-rules)[![GitHub Tests Action Status](https://camo.githubusercontent.com/a1cbce5db40c75aac2ff2c28d2718460df6f80e49b2cfcf243de1f3300db6cf9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f68696861686f2f726563746f722d72756c65732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/hihaho/rector-rules/actions/workflows/run-tests.yml)[![GitHub PHPStan Action Status](https://camo.githubusercontent.com/a4325b8d60a6de72013a0743d0c2a4bcc6edd4d3434b5deffb7c483f4501a1a9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616e6465726d756c6c65722f73746f7077617463682f7068707374616e2e796d6c3f6272616e63683d6d61696e266c6162656c3d7068707374616e267374796c653d666c61742d737175617265)](https://github.com/sandermuller/stopwatch/actions?query=workflow%3Aphpstan+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/a65a03a11fa70b3f78521c61fa195d73339286b07db390a7e2cf50d95966341f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68696861686f2f726563746f722d72756c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hihaho/rector-rules)[![License](https://camo.githubusercontent.com/c9bb2d6336b8d64fe257a16934e052b6ae51478b35e91eaceeeee75978c70b01/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68696861686f2f726563746f722d72756c65732e7376673f7374796c653d666c61742d737175617265)](LICENSE)

[Rector](https://getrector.com/) rules that enforce the Laravel conventions from the [Hihaho Development Guidelines](https://guidelines.hihaho.com/): naming, routing, migration safety, and import aliasing.

For the static-analysis counterparts (rules that flag code but don't rewrite it), see [`hihaho/phpstan-rules`](https://github.com/hihaho/phpstan-rules).

Requirements
------------

[](#requirements)

- PHP `^8.3`
- Rector `^2.0`
- Laravel `^11`, `^12`, or `^13` (rules reference `Illuminate\…` classes)

Installation
------------

[](#installation)

```
composer require hihaho/rector-rules --dev
```

Usage
-----

[](#usage)

Add the desired rule sets to your `rector.php`:

```
use Hihaho\RectorRules\Set\HihahoSetList;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withSets([
        HihahoSetList::ALL, // all rules
    ]);
```

Or pick individual sets:

```
->withSets([
    HihahoSetList::NAMING,
    HihahoSetList::ROUTING,
    HihahoSetList::MIGRATIONS,
    HihahoSetList::IMPORTS,
])
```

Rule Sets
---------

[](#rule-sets)

### Naming (`HihahoSetList::NAMING`)

[](#naming-hihahosetlistnaming)

Enforces class naming suffixes based on the parent class.

RuleDescription`AddCommandSuffixRector`Classes extending `Command` must end with `Command``AddMailSuffixRector`Classes extending `Mailable` must end with `Mail``AddNotificationSuffixRector`Classes extending `Notification` must end with `Notification``AddResourceSuffixRector``JsonResource` subclasses end with `Resource`; `ResourceCollection` subclasses end with `ResourceCollection````
-class NotifyUsers extends Command
+class NotifyUsersCommand extends Command
```

**Why?** Suffixes make artifact types obvious from the class name alone, and they prevent collisions like `App\Mail\Welcome` vs `App\Notifications\Welcome` from biting you later. IDE search and `grep` are a lot more useful when the convention holds.

**Skipped:** abstract classes, classes already suffixed correctly, and (in the Resource rule only) `JsonResource` subclasses whose names already end in `Collection`. Those look like naming mistakes; renaming them to `FooCollectionResource` would just bury the bug.

### Routing (`HihahoSetList::ROUTING`)

[](#routing-hihahosetlistrouting)

Enforces consistent route definitions. Only applies to files under a `routes/` directory (and skips anything under `/vendor/`).

RuleDescription`NormalizeRoutePathRector`Strip leading/trailing slashes and collapse consecutive slashes`RouteGroupArrayToMethodsRector`Convert array-based route groups to fluent method chaining```
-Route::get('/about', fn () => 'about');
+Route::get('about', fn () => 'about');
```

```
-Route::group(['middleware' => 'web', 'prefix' => 'admin', 'name' => 'admin.'], function (): void {
+Route::middleware('web')->prefix('admin')->name('admin.')->group(function (): void {
     Route::get('dashboard', fn () => 'dashboard');
 });
```

**Why?** Fluent chains produce cleaner diffs than option arrays, and they're easier to extend when you tack on another middleware or prefix. Path normalization prevents duplicate routes from `/foo` vs `foo/`.

**Scope:**

- `NormalizeRoutePathRector` only rewrites `Route::get|post|put|patch|delete|any|head`. `Route::match`, `Route::redirect`, `Route::view`, and custom verbs are left untouched.
- `RouteGroupArrayToMethodsRector` only rewrites groups where every array key is in the supported set: `middleware`, `prefix`, `name` / `as`, `namespace`, `domain`, `where`, `excluded_middleware`, `scope_bindings`. Unknown keys, positional (no-key) arrays, and empty arrays are left as-is to avoid dropping configuration silently.

### Migrations (`HihahoSetList::MIGRATIONS`)

[](#migrations-hihahosetlistmigrations)

Enforces self-contained, production-safe migrations. Only applies to files in the `database/migrations/` directory.

RuleDescription`RemoveAfterColumnPositioningRector`Remove `->after()` column positioning calls (prevents disabling INSTANT DDL)`InlineMigrationConstantsRector`Inline class constants (string, int, float, bool, null). Enum cases are left alone.```
 Schema::table('users', function (Blueprint $table): void {
-    $table->string('description')->after('name');
-    $table->boolean(Video::CALIPER_ENABLED)->nullable();
+    $table->string('description');
+    $table->boolean('caliper_enabled')->nullable();
 });
```

**Why?** Migrations must be self-contained. Using `->after()` can disable MySQL's INSTANT DDL optimization on large tables. Referencing model constants creates a dependency that breaks if the constant is later renamed or removed.

**Scope:**

- `RemoveAfterColumnPositioningRector` only strips `->after()` calls whose receiver is a `ColumnDefinition` (e.g. `$table->string('x')->after('y')`). Blueprint's two-arg scoping form (`$table->after($col, Closure)`) and unrelated `->after()` methods (e.g. `Collection::after`) are left alone.
- `InlineMigrationConstantsRector` skips enum cases so `Status::Active` keeps its enum semantics instead of silently becoming a string literal.

### Imports (`HihahoSetList::IMPORTS`)

[](#imports-hihahosetlistimports)

Configurable import aliasing to prevent ambiguous class names.

RuleDescription`AliasImportRector`Rename imports using configured aliasesDefault configuration:

- `Illuminate\Database\Eloquent\Builder` → `EloquentQueryBuilder`
- `Illuminate\Database\Query\Builder` → `QueryBuilder`
- `Illuminate\Database\Eloquent\Collection` → `EloquentCollection`

```
-use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Builder as EloquentQueryBuilder;

-public function scopeActive(Builder $query): Builder
+public function scopeActive(EloquentQueryBuilder $query): EloquentQueryBuilder
```

All references in the file are updated, including:

- Flat `use` and grouped `use Foo\{A, B};` imports
- Type hints, `new` expressions, `extends`, `instanceof`
- PHPDoc tags (`@param`, `@return`, `@var`, `@method`, `@property`, `@mixin`) on classes, interfaces, traits, enums, methods, properties, and functions

**Why?** `Illuminate\Database\Eloquent\Builder` and `Illuminate\Database\Query\Builder` share a short name, so an unaliased `Builder` type hint tells you nothing about which one the method expects. Consistent aliases show which `Builder` is in play without having to look at the `use` block, and they free up the short name if the app wants its own.

**Collision safety:** if the target alias is already used by another import in the same file (e.g. the file already has a `use App\Queries\EloquentQueryBuilder;`), the rule leaves that file alone rather than producing a PHP-fatal `use X as Y` collision. Rename the conflicting import or configure a different alias to proceed.

#### Custom alias configuration

[](#custom-alias-configuration)

Override the default aliases in your `rector.php`:

```
use Hihaho\RectorRules\Rector\Import\AliasImportRector;

->withConfiguredRule(AliasImportRector::class, [
    'Illuminate\Database\Eloquent\Builder' => 'EloquentQueryBuilder',
    'Illuminate\Database\Query\Builder' => 'QueryBuilder',
    'Illuminate\Database\Eloquent\Collection' => 'EloquentCollection',
])
```

Covered by upstream Rector
--------------------------

[](#covered-by-upstream-rector)

Some rules in [`hihaho/phpstan-rules`](https://github.com/hihaho/phpstan-rules) have no counterpart here because the fix already ships in an upstream Rector set. Enable the upstream set instead of waiting for a rule in this package.

PHPStan ruleUpstream setNotes`onlyAllowFacadeAliasInBlade``LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES`Rewrites `use Route;` to `use Illuminate\Support\Facades\Route;` (and siblings)```
use RectorLaravel\Set\LaravelSetList;

->withSets([LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES])
```

Testing
-------

[](#testing)

```
composer test
```

Runs the full Pest suite. For the same quality gate the CI runs (Pint + Rector + PHPStan + tests), use `composer qa`.

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for recent changes.

Contributing
------------

[](#contributing)

Pull requests and issues are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for the local setup, fixture format, and what CI will check.

Security
--------

[](#security)

Please report security issues privately. See [SECURITY.md](SECURITY.md) for how.

Credits
-------

[](#credits)

- [Hihaho](https://github.com/hihaho)
- [All contributors](https://github.com/hihaho/rector-rules/contributors)

License
-------

[](#license)

MIT. See [LICENSE](LICENSE).

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance94

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

58d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31760627?v=4)[hihaho](/maintainers/hihaho)[@hihaho](https://github.com/hihaho)

---

Top Contributors

[![SanderMuller](https://avatars.githubusercontent.com/u/9074391?v=4)](https://github.com/SanderMuller "SanderMuller (31 commits)")

---

Tags

laravelstatic analysisCode stylerectorrector-ruleshihahoconventionsrector-extension

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hihaho-rector-rules/health.svg)

```
[![Health](https://phpackages.com/badges/hihaho-rector-rules/health.svg)](https://phpackages.com/packages/hihaho-rector-rules)
```

###  Alternatives

[mrpunyapal/rector-pest

Rector upgrade rules for Pest - refactoring and best practices for Pest testing framework

6455.5k49](/packages/mrpunyapal-rector-pest)[malukenho/docheader

A small library to check header docs

69407.8k137](/packages/malukenho-docheader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
