Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Log | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| applied | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| record | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Quma\Migrations; |
| 6 | |
| 7 | use Celemas\Quma\Database; |
| 8 | use Celemas\Quma\Environment; |
| 9 | |
| 10 | final readonly class Log |
| 11 | { |
| 12 | public function __construct( |
| 13 | private Environment $env, |
| 14 | private Planner $planner, |
| 15 | ) {} |
| 16 | |
| 17 | /** @return list<string> */ |
| 18 | public function applied(Database $db): array |
| 19 | { |
| 20 | $table = $this->env->table; |
| 21 | $column = $this->env->columnMigration; |
| 22 | $migrations = $db->execute("SELECT {$column} AS migration FROM {$table};")->all(); |
| 23 | |
| 24 | return array_map( |
| 25 | static fn(array $migration): string => (string) $migration['migration'], |
| 26 | $migrations, |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | public function record(Database $db, string $namespace, string $migration): void |
| 31 | { |
| 32 | $table = $this->env->table; |
| 33 | $column = $this->env->columnMigration; |
| 34 | |
| 35 | $db->execute( |
| 36 | "INSERT INTO {$table} ({$column}) VALUES (:migration)", |
| 37 | ['migration' => $this->planner->migrationId($namespace, $migration)], |
| 38 | )->run(); |
| 39 | } |
| 40 | } |