Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
19 / 19
9.23% covered (danger)
9.23%
6 / 65
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Plan
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
19 / 19
9.23% covered (danger)
9.23%
6 / 65
100.00% covered (success)
100.00%
2 / 2
55.86
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 show
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
18 / 18
7.81% covered (danger)
7.81%
5 / 64
100.00% covered (success)
100.00%
1 / 1
45.39
1<?php
2
3declare(strict_types=1);
4
5namespace Celema\Quma\Migrations;
6
7use Celema\Console\Io;
8use Celema\Quma\Environment;
9
10final readonly class Plan
11{
12    public function __construct(
13        private Environment $env,
14        private Planner $planner,
15        private Log $log,
16        private Io $io,
17    ) {}
18
19    /** @param list<string> $migrations */
20    public function show(string $namespace, array $migrations, bool $tableExists): int
21    {
22        $io = $this->io;
23        $appliedMigrations = $tableExists ? $this->log->applied($this->env->db) : [];
24        $pendingMigrations = $this->planner->pendingMigrations(
25            $namespace,
26            $migrations,
27            $appliedMigrations,
28        );
29        $numPending = count($pendingMigrations);
30        $plural = $numPending > 1 ? 's' : '';
31
32        $io->line("\n<bright-red>Notice</bright-red>: Plan only");
33
34        if (!$tableExists) {
35            $io->line("Would create migrations table '%s'", $this->env->table);
36        }
37
38        if ($numPending === 0) {
39            $io->line("\nNo pending migrations");
40        } else {
41            $io->line("Would apply {$numPending} migration{$plural}:");
42
43            foreach ($pendingMigrations as $migration) {
44                $io->line('  - %s', basename($migration));
45            }
46        }
47
48        $io->write("\nNo migrations were executed. ");
49
50        if ($this->env->driver === 'mysql') {
51            $io->line(
52                'MySQL migrations are plan-only without --apply because DDL statements can cause implicit commits.',
53            );
54            $io->line('Use --apply to run them.');
55        } else {
56            $io->line('Use --test-run --yes to execute inside a rollback transaction, or --apply to commit.');
57        }
58
59        return 0;
60    }
61}