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