Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
MetadataTable
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
6
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
 create
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3declare(strict_types=1);
4
5namespace Celema\Quma\Migrations;
6
7use Celema\Console\Io;
8use Celema\Quma\Database;
9use Celema\Quma\Environment;
10use Throwable;
11
12final readonly class MetadataTable
13{
14    public function __construct(
15        private Environment $env,
16        private Io $io,
17    ) {}
18
19    public function create(Database $db): int
20    {
21        $env = $this->env;
22        $io = $this->io;
23
24        if ($env->checkIfMigrationsTableExists($db)) {
25            $io->echolnErr("Table '{$env->table}' already exists. Aborting");
26
27            return 1;
28        }
29
30        $ddl = $env->getMigrationsTableDDL();
31
32        if ($ddl !== false) {
33            try {
34                $db->execute($ddl)->run();
35                $io->echoln("<bright-green>Success</bright-green>: Created table '{$env->table}'");
36
37                return 0;
38
39                // Would require to create additional errornous DDL or to
40                // setup a different test database. Too much effort.
41                // @codeCoverageIgnoreStart
42            } catch (Throwable $e) {
43                $io->echolnErr("<bright-red>Error</bright-red>: While trying to create table '{$env->table}'");
44                $io->echolnErr($io->escape($e->getMessage()));
45
46                if ($env->showStacktrace) {
47                    $io->echolnErr($io->escape($e->getTraceAsString()));
48                }
49
50                return 1;
51
52                // @codeCoverageIgnoreEnd
53            }
54        }
55
56        // Cannot be reliably tested.
57        // Would require an unsupported driver to be installed.
58        // @codeCoverageIgnoreStart
59        $io->echolnErr("PDO driver '{$env->driver}' not supported. Aborting");
60
61        return 1;
62
63        // @codeCoverageIgnoreEnd
64    }
65}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

MetadataTable->__construct
15        private Environment $env,
16        private Io $io,
17    ) {}
MetadataTable->create
19    public function create(Database $db): int
20    {
21        $env = $this->env;
22        $io = $this->io;
23
24        if ($env->checkIfMigrationsTableExists($db)) {
25            $io->echolnErr("Table '{$env->table}' already exists. Aborting");
26
27            return 1;
30        $ddl = $env->getMigrationsTableDDL();
31
32        if ($ddl !== false) {
33            try {
34                $db->execute($ddl)->run();
35                $io->echoln("<bright-green>Success</bright-green>: Created table '{$env->table}'");
36
37                return 0;