MigrationGenerator
Generates a new migration file — the `migrate --create` boilerplate, with no database dependency (it only writes a file).
By default it produces a named, timestamped Migration subclass with
empty // TODO up() / down() bodies, the intent written by a human
afterwards. create() can also pre-fill those bodies with provided
PHP code — the hook the arango:analyzers --fix action uses to emit a
ready-to-review repair migration rather than an empty shell.
Tags
Table of Contents
Properties
- $namespace : string
- $path : string
Methods
- __construct() : mixed
- create() : string
- Writes a new `Version<timestamp>_<Label>.php` file and returns its path.
- body() : string
- Indents a (possibly multi-line) code body to the method-body column of the generated file, leaving blank lines empty.
- label() : string
- Turns a free description into a PascalCase class label.
- skeleton() : string
- The body of a generated migration file.
- timestamp() : string
- The current `YmdHis` version prefix (overridable in tests).
- useBlock() : string
- Builds the `use …;` import block — the always-needed {@see Migration} plus the caller-supplied class names, deduplicated and sorted so the output is deterministic.
Properties
$namespace
protected
string
$namespace
= ''
$path
protected
string
$path
Methods
__construct()
public
__construct(string $path[, string $namespace = '' ]) : mixed
Parameters
- $path : string
-
The directory the version file is written to.
- $namespace : string = ''
-
The PHP namespace the generated class is declared in.
create()
Writes a new `Version<timestamp>_<Label>.php` file and returns its path.
public
create(string $description[, string|null $timestamp = null ][, string|null $up = null ][, string|null $down = null ][, array<int, string> $uses = [] ]) : string
By default the up() / down() bodies are left as a // TODO shell (the
migrate --create case). When $up (and optionally $down) is given,
that PHP code is injected verbatim into the method bodies — the hook the
arango:analyzers --fix action uses to write a ready-to-review repair
migration instead of an empty shell.
Parameters
- $description : string
-
A human description (also turned into the class label).
- $timestamp : string|null = null
-
The
YmdHisversion prefix — injected for determinism; defaults to now. - $up : string|null = null
-
PHP code for the
up()body (without the method wrapper);nullkeeps the// TODOshell. - $down : string|null = null
-
PHP code for the
down()body;nullkeeps the// TODOshell. - $uses : array<int, string> = []
-
Extra fully-qualified class names to
useat the top of the file (so an injected body can reference them by their short name).Migrationis always imported.
Tags
Return values
string —The path of the created file.
body()
Indents a (possibly multi-line) code body to the method-body column of the generated file, leaving blank lines empty.
protected
body(string $code) : string
Parameters
- $code : string
Return values
stringlabel()
Turns a free description into a PascalCase class label.
protected
label(string $description) : string
Parameters
- $description : string
Return values
stringskeleton()
The body of a generated migration file.
protected
skeleton(string $class, string $description[, string|null $up = null ][, string|null $down = null ][, array<int, string> $uses = [] ]) : string
Parameters
- $class : string
-
The class name.
- $description : string
-
The human description.
- $up : string|null = null
-
PHP code for the
up()body;nullfalls back to the// TODOshell. - $down : string|null = null
-
PHP code for the
down()body;nullfalls back to the// TODOshell. - $uses : array<int, string> = []
-
Extra fully-qualified class names to import (deduplicated and sorted with
Migration).
Return values
stringtimestamp()
The current `YmdHis` version prefix (overridable in tests).
protected
timestamp() : string
Return values
stringuseBlock()
Builds the `use …;` import block — the always-needed {@see Migration} plus the caller-supplied class names, deduplicated and sorted so the output is deterministic.
protected
useBlock(array<int, string> $uses) : string
Parameters
- $uses : array<int, string>
-
Extra fully-qualified class names.