Skip to content

Commit f06010b

Browse files
committed
Improve configuration structure
1 parent 01ddf88 commit f06010b

2 files changed

Lines changed: 76 additions & 35 deletions

File tree

README.md

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,56 @@ includes:
1515
- vendor/bellangelo/phpstan-migration-rules/extension.neon
1616
```
1717

18-
## Rule catalog
18+
## Configuration
1919

20-
Each rule below applies to migration files, regardless of framework, unless stated otherwise.
20+
All rules are enabled by default. You can customize behavior in your `phpstan.neon`:
2121

22-
### Rule: `EnforceCollationRule`
23-
Enforces that table definitions explicitly define a collation.
24-
> Prevents relying on database defaults, which may differ between environments.
22+
```neon
23+
parameters:
24+
migrationRules:
25+
requiredCollation: utf8mb4 # Default is utf8
26+
27+
phinx:
28+
enforceCollation: true
29+
forbidAfter: true
30+
forbidMultipleTableCreations: true
2531
26-
#### Configuration
32+
laravel:
33+
enforceCollation: true
34+
forbidAfter: true
35+
forbidMultipleTableCreations: true
36+
```
2737

28-
```yaml
38+
If you only use one framework, disable the other to avoid unnecessary processing:
39+
40+
```neon
2941
parameters:
30-
phpstanMigrationRules:
31-
requiredCollation: utf8mb4 # Default is utf8
42+
migrationRules:
43+
phinx:
44+
enforceCollation: false
45+
forbidAfter: false
46+
forbidMultipleTableCreations: false
3247
```
3348

34-
#### Support
49+
## Rule catalog
50+
51+
Each rule below applies to migration files for both Phinx and Laravel, unless stated otherwise.
52+
53+
### Rule: `EnforceCollationRule`
54+
Enforces that table definitions explicitly define a collation.
55+
> Prevents relying on database defaults, which may differ between environments.
3556
3657
| Framework | How collation is detected |
3758
|---|---|
38-
| [Phinx](./src/Rules/Phinx/EnforceCollationRule.php) | `table('name', ['collation' => '…'])` | [Phinx/EnforceCollationRule](./src/Rules/Phinx/EnforceCollationRule.php) |
39-
| [Laravel]((./src/Rules/Laravel/EnforceCollationRule.php)) | `$table->collation('…')` or `$table->collation = '…'` inside the Blueprint callback |
59+
| [Phinx](./src/Rules/Phinx/EnforceCollationRule.php) | `table('name', ['collation' => '…'])` |
60+
| [Laravel](./src/Rules/Laravel/EnforceCollationRule.php) | `$table->collation('…')` or `$table->collation = '…'` inside the Blueprint callback |
4061

4162
---
4263

4364
### Rule: `ForbidAfterRule`
4465
Forbids column positioning via `after`.
4566
> May trigger full table rewrites or long locks, unsafe for large or production tables.
4667
47-
#### Support
48-
4968
| Framework | Forbidden usage |
5069
|---|---|
5170
| [Phinx](./src/Rules/Phinx/ForbidAfterRule.php) | `addColumn(..., ['after' => 'column'])` |
@@ -55,11 +74,7 @@ Forbids column positioning via `after`.
5574

5675
### Rule: `ForbidMultipleTableCreationsRule`
5776
Ensures each migration creates at most one table.
58-
> Improves rollback safety and migration clarity
59-
60-
---
61-
62-
#### Support
77+
> Improves rollback safety and migration clarity.
6378
6479
| Framework | What counts as a table creation |
6580
|---|---|

extension.neon

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,69 @@
11
parametersSchema:
2-
phpstanMigrationRules: structure([
2+
migrationRules: structure([
33
requiredCollation: string()
4+
phinx: structure([
5+
enforceCollation: bool()
6+
forbidAfter: bool()
7+
forbidMultipleTableCreations: bool()
8+
])
9+
laravel: structure([
10+
enforceCollation: bool()
11+
forbidAfter: bool()
12+
forbidMultipleTableCreations: bool()
13+
])
414
])
515

616
parameters:
7-
phpstanMigrationRules:
17+
migrationRules:
818
requiredCollation: utf8
19+
phinx:
20+
enforceCollation: true
21+
forbidAfter: true
22+
forbidMultipleTableCreations: true
23+
laravel:
24+
enforceCollation: true
25+
forbidAfter: true
26+
forbidMultipleTableCreations: true
27+
28+
conditionalTags:
29+
PhpStanMigrationRules\Rules\Phinx\EnforceCollationRule:
30+
phpstan.rules.rule:
31+
condition: %migrationRules.phinx.enforceCollation%
32+
PhpStanMigrationRules\Rules\Phinx\ForbidAfterRule:
33+
phpstan.rules.rule:
34+
condition: %migrationRules.phinx.forbidAfter%
35+
PhpStanMigrationRules\Rules\Phinx\ForbidMultipleTableCreationsRule:
36+
phpstan.rules.rule:
37+
condition: %migrationRules.phinx.forbidMultipleTableCreations%
38+
PhpStanMigrationRules\Rules\Laravel\EnforceCollationRule:
39+
phpstan.rules.rule:
40+
condition: %migrationRules.laravel.enforceCollation%
41+
PhpStanMigrationRules\Rules\Laravel\ForbidAfterRule:
42+
phpstan.rules.rule:
43+
condition: %migrationRules.laravel.forbidAfter%
44+
PhpStanMigrationRules\Rules\Laravel\ForbidMultipleTableCreationsRule:
45+
phpstan.rules.rule:
46+
condition: %migrationRules.laravel.forbidMultipleTableCreations%
947

1048
services:
1149
-
1250
class: PhpStanMigrationRules\Rules\Phinx\EnforceCollationRule
1351
arguments:
14-
requiredCollation: %phpstanMigrationRules.requiredCollation%
15-
tags:
16-
- phpstan.rules.rule
52+
requiredCollation: %migrationRules.requiredCollation%
1753

1854
-
1955
class: PhpStanMigrationRules\Rules\Phinx\ForbidAfterRule
20-
tags:
21-
- phpstan.rules.rule
2256

2357
-
2458
class: PhpStanMigrationRules\Rules\Phinx\ForbidMultipleTableCreationsRule
25-
tags:
26-
- phpstan.rules.rule
2759

2860
-
2961
class: PhpStanMigrationRules\Rules\Laravel\EnforceCollationRule
3062
arguments:
31-
requiredCollation: %phpstanMigrationRules.requiredCollation%
32-
tags:
33-
- phpstan.rules.rule
63+
requiredCollation: %migrationRules.requiredCollation%
3464

3565
-
3666
class: PhpStanMigrationRules\Rules\Laravel\ForbidAfterRule
37-
tags:
38-
- phpstan.rules.rule
3967

4068
-
4169
class: PhpStanMigrationRules\Rules\Laravel\ForbidMultipleTableCreationsRule
42-
tags:
43-
- phpstan.rules.rule

0 commit comments

Comments
 (0)