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

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
14        private Environment $env,
15    ) {}
MetadataTable->create
17    public function create(Database $db): int
18    {
19        $env = $this->env;
20
21        if ($env->checkIfMigrationsTableExists($db)) {
22            echo "Table '{$env->table}' already exists. Aborting\n";
23
24            return 1;
27        $ddl = $env->getMigrationsTableDDL();
28
29        if ($ddl !== false) {
30            try {
31                $db->execute($ddl)->run();
32                echo "\033[1;32mSuccess\033[0m: Created table '{$env->table}'\n";
33
34                return 0;