PHPackages                             bellangelo/phpstan-migration-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. bellangelo/phpstan-migration-rules

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

bellangelo/phpstan-migration-rules
==================================

PHPStan rules for database migration tools (Phinx, Symfony, Laravel)

v0.4.4(3d ago)685.4k↓82.5%1[1 issues](https://github.com/Bellangelo/phpstan-migration-rules/issues)[1 PRs](https://github.com/Bellangelo/phpstan-migration-rules/pulls)MITPHPPHP ^8.3CI passing

Since Dec 28Pushed 3mo agoCompare

[ Source](https://github.com/Bellangelo/phpstan-migration-rules)[ Packagist](https://packagist.org/packages/bellangelo/phpstan-migration-rules)[ RSS](/packages/bellangelo-phpstan-migration-rules/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (24)Versions (13)Used By (0)

PHPStan Rules for Database Migrations
=====================================

[](#phpstan-rules-for-database-migrations)

A collection of PHPStan rules to enforce best practices and standards in database migration files for Phinx and Laravel / Illuminate.

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

[](#installation)

```
composer require --dev bellangelo/phpstan-migration-rules
```

The extension will be automatically registered if you have `phpstan/extension-installer` installed. Otherwise, add it manually to your `phpstan.neon`:

```
includes:
    - vendor/bellangelo/phpstan-migration-rules/extension.neon
```

Configuration
-------------

[](#configuration)

All rules are enabled by default. You can customize behavior in your `phpstan.neon`:

```
parameters:
    migrationRules:
        requiredCollation: utf8mb4 # Default is utf8

        phinx:
            enforceCollation: true
            forbidAfter: true
            forbidEnumColumn: true
            forbidRawSql: true
            forbidMultipleTableCreations: true

        laravel:
            enforceCollation: true
            forbidAfter: true
            forbidEnumColumn: true
            forbidRawSql: true
            forbidMultipleTableCreations: true
```

If you only use one framework, disable the other to avoid unnecessary processing:

```
parameters:
    migrationRules:
        phinx:
            enforceCollation: false
            forbidAfter: false
            forbidEnumColumn: false
            forbidRawSql: false
            forbidMultipleTableCreations: false
```

Rule catalog
------------

[](#rule-catalog)

Each rule below applies to migration files for both Phinx and Laravel, unless stated otherwise.

### Rule: `EnforceCollationRule`

[](#rule-enforcecollationrule)

Enforces that table definitions explicitly define a collation.

> Prevents relying on database defaults, which may differ between environments.

FrameworkHow collation is detected[Phinx](./src/Rules/Phinx/EnforceCollationRule.php)`table('name', ['collation' => '…'])`[Laravel](./src/Rules/Laravel/EnforceCollationRule.php)`$table->collation('…')` or `$table->collation = '…'` inside the Blueprint callback---

### Rule: `ForbidAfterRule`

[](#rule-forbidafterrule)

Forbids column positioning via `after`.

> May trigger full table rewrites or long locks, unsafe for large or production tables.

FrameworkForbidden usage[Phinx](./src/Rules/Phinx/ForbidAfterRule.php)`addColumn(..., ['after' => 'column'])`[Laravel](./src/Rules/Laravel/ForbidAfterRule.php)`$table->string('x')->after('y')`---

### Rule: `ForbidEnumColumnRule`

[](#rule-forbidenumcolumnrule)

Forbids the use of `enum` column types in migrations.

> Modifying enum values requires a full `ALTER TABLE`, which can cause long locks on large tables. Use a string column with application-level validation instead.

FrameworkForbidden usage[Phinx](./src/Rules/Phinx/ForbidEnumColumnRule.php)`addColumn('col', 'enum', ['values' => [...]])`[Laravel](./src/Rules/Laravel/ForbidEnumColumnRule.php)`$table->enum('col', [...])`---

### Rule: `ForbidRawSqlRule`

[](#rule-forbidrawsqlrule)

Forbids raw SQL execution inside migrations.

> Raw SQL bypasses the schema builder, making migrations harder to review, less portable, and prone to errors.

FrameworkForbidden usage[Phinx](./src/Rules/Phinx/ForbidRawSqlRule.php)`$this->execute('...')`, `$this->query('...')`[Laravel](./src/Rules/Laravel/ForbidRawSqlRule.php)`DB::statement('...')`, `DB::unprepared('...')`---

### Rule: `ForbidMultipleTableCreationsRule`

[](#rule-forbidmultipletablecreationsrule)

Ensures each migration creates at most one table.

> Improves rollback safety and migration clarity.

FrameworkWhat counts as a table creation[Phinx](./src/Rules/Phinx/ForbidMultipleTableCreationsRule.php)Multiple calls to `create()` on table instances[Laravel](./src/Rules/Laravel/ForbidMultipleTableCreationsRule.php)Multiple `Schema::create()` calls in the same migration

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance85

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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 ~17 days

Recently: every ~24 days

Total

12

Last Release

3d ago

PHP version history (2 changes)v0.1.0PHP ^7.4 || ^8.0

v0.4.4PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9512427?v=4)[Aggelos Bellos](/maintainers/Bellangelo)[@Bellangelo](https://github.com/Bellangelo)

---

Top Contributors

[![Bellangelo](https://avatars.githubusercontent.com/u/9512427?v=4)](https://github.com/Bellangelo "Bellangelo (68 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bellangelo-phpstan-migration-rules/health.svg)

```
[![Health](https://phpackages.com/badges/bellangelo-phpstan-migration-rules/health.svg)](https://phpackages.com/packages/bellangelo-phpstan-migration-rules)
```

###  Alternatives

[pqrs/l5b-crud

CRUD artisan command for rappasoft/laravel-5-boilerplate

2116.8k](/packages/pqrs-l5b-crud)

PHPackages © 2026

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