bellangelo / phpstan-migration-rules
PHPStan rules for database migration tools (Phinx, Symfony, Laravel)
Installs: 339
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:phpstan-extension
pkg:composer/bellangelo/phpstan-migration-rules
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- illuminate/database: ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0
- illuminate/support: ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.5|^10.0
- rector/rector: ^2.3
- robmorgan/phinx: ^0.13
- squizlabs/php_codesniffer: ^4.0
- staabm/annotate-pull-request-from-checkstyle: ^1.8
README
A collection of PHPStan rules to enforce best practices and standards in database migration files for Phinx and Laravel / Illuminate.
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
Rule catalog
Each rule below applies to migration files, regardless of framework, unless stated otherwise.
Rule: EnforceCollationRule
Enforces that table definitions explicitly define a collation.
Prevents relying on database defaults, which may differ between environments.
Configuration
parameters: phpstanMigrationRules: requiredCollation: utf8mb4 # Default is utf8
Support
| Framework | How collation is detected |
|---|---|
| Phinx | table('name', ['collation' => '…']) |
| Laravel | $table->collation('…') or $table->collation = '…' inside the Blueprint callback |
Rule: ForbidAfterRule
Forbids column positioning via after.
May trigger full table rewrites or long locks, unsafe for large or production tables.
Support
| Framework | Forbidden usage |
|---|---|
| Phinx | addColumn(..., ['after' => 'column']) |
| Laravel | $table->string('x')->after('y') |
Rule: ForbidMultipleTableCreationsRule
Ensures each migration creates at most one table.
Improves rollback safety and migration clarity
Support
| Framework | What counts as a table creation |
|---|---|
| Phinx | Multiple calls to create() on table instances |
| Laravel | Multiple Schema::create() calls in the same migration |