@@ -40,6 +40,60 @@ class MyNewMigration extends BaseMigration
4040}
4141```
4242
43+ ### Anonymous Migration Classes
44+
45+ Migrations also supports generating anonymous migration classes, which use PHP's
46+ anonymous class feature instead of named classes. This style is useful for:
47+
48+ - Avoiding namespace declarations
49+ - Better PHPCS compatibility (no class name to filename matching required)
50+ - Simpler file structure without named class constraints
51+ - More readable filenames like ` 2024_12_08_120000_CreateProducts.php `
52+
53+ To generate an anonymous migration class, use the ` --style anonymous ` option:
54+
55+ ``` bash
56+ $ bin/cake bake migration CreateProducts --style anonymous
57+ ```
58+
59+ This generates a migration file using an anonymous class:
60+
61+ ``` php
62+ <?php
63+ declare(strict_types=1);
64+
65+ use Migrations\BaseMigration;
66+
67+ return new class extends BaseMigration
68+ {
69+ /**
70+ * Change Method.
71+ *
72+ * More information on this method is available here:
73+ * https://book.cakephp.org/migrations/5/en/migrations.html#the-change-method
74+ * @return void
75+ */
76+ public function change(): void
77+ {
78+ }
79+ };
80+ ```
81+
82+ Both traditional and anonymous migration classes work identically at runtime and can
83+ be used interchangeably within the same project.
84+
85+ You can set the default migration style globally in your application configuration:
86+
87+ ``` php
88+ // In config/app.php or config/app_local.php
89+ 'Migrations' => [
90+ 'style' => 'anonymous', // or 'traditional'
91+ ],
92+ ```
93+
94+ This configuration also applies to seeds, allowing you to use consistent styling
95+ across your entire project.
96+
4397## The Change Method
4498
4599Migrations supports 'reversible migrations'. In many scenarios, you
0 commit comments