-
-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy pathMigrationsFlattener.php
74 lines (67 loc) · 2.63 KB
/
MigrationsFlattener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
namespace Doctrine\Bundle\MigrationsBundle\Collector;
use DateTimeImmutable;
use Doctrine\Migrations\Metadata\AvailableMigration;
use Doctrine\Migrations\Metadata\AvailableMigrationsList;
use Doctrine\Migrations\Metadata\ExecutedMigration;
use Doctrine\Migrations\Metadata\ExecutedMigrationsList;
use ReflectionClass;
use function array_map;
/** @final */
class MigrationsFlattener
{
/**
* @return array{
* version: string,
* is_new: true,
* is_unavailable: bool,
* description: string,
* executed_at: null,
* execution_time: null,
* file: string|false,
* }[]
*/
public function flattenAvailableMigrations(AvailableMigrationsList $migrationsList): array
{
return array_map(static function (AvailableMigration $migration) {
return [
'version' => (string) $migration->getVersion(),
'is_new' => true,
'is_unavailable' => false,
'description' => $migration->getMigration()->getDescription(),
'executed_at' => null,
'execution_time' => null,
'file' => (new ReflectionClass($migration->getMigration()))->getFileName(),
];
}, $migrationsList->getItems());
}
/**
* @return array{
* version: string,
* is_new: false,
* is_unavailable: bool,
* description: string|null,
* executed_at: DateTimeImmutable|null,
* execution_time: float|null,
* file: string|false|null,
* }[]
*/
public function flattenExecutedMigrations(ExecutedMigrationsList $migrationsList, AvailableMigrationsList $availableMigrations): array
{
return array_map(static function (ExecutedMigration $migration) use ($availableMigrations) {
$availableMigration = $availableMigrations->hasMigration($migration->getVersion())
? $availableMigrations->getMigration($migration->getVersion())->getMigration()
: null;
return [
'version' => (string) $migration->getVersion(),
'is_new' => false,
'is_unavailable' => $availableMigration === null,
'description' => $availableMigration !== null ? $availableMigration->getDescription() : null,
'executed_at' => $migration->getExecutedAt(),
'execution_time' => $migration->getExecutionTime(),
'file' => $availableMigration !== null ? (new ReflectionClass($availableMigration))->getFileName() : null,
];
}, $migrationsList->getItems());
}
}