A collection of PHPStan rules to enforce best practices and standards in database migration files for Phinx and Laravel / Illuminate.
composer require --dev bellangelo/phpstan-migration-rulesThe 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.neonEach rule below applies to migration files, regardless of framework, unless stated otherwise.
Enforces that table definitions explicitly define a collation.
Prevents relying on database defaults, which may differ between environments.
parameters:
phpstanMigrationRules:
requiredCollation: utf8mb4 # Default is utf8| Framework | How collation is detected |
|---|---|
| Phinx | table('name', ['collation' => '…']) |
| Laravel | $table->collation('…') or $table->collation = '…' inside the Blueprint callback |
Forbids column positioning via after.
May trigger full table rewrites or long locks, unsafe for large or production tables.
| Framework | Forbidden usage |
|---|---|
| Phinx | addColumn(..., ['after' => 'column']) |
| Laravel | $table->string('x')->after('y') |
Ensures each migration creates at most one table.
Improves rollback safety and migration clarity
| Framework | What counts as a table creation |
|---|---|
| Phinx | Multiple calls to create() on table instances |
| Laravel | Multiple Schema::create() calls in the same migration |