Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MetadataTable | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| create | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
5 | |||
| 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 | use Throwable; |
| 10 | |
| 11 | final 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 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 14 | private Environment $env, |
| 15 | ) {} |
| 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; |
| 17 | public function create(Database $db): int |
| 18 | { |
| 19 | $env = $this->env; |
| 20 | |
| 21 | if ($env->checkIfMigrationsTableExists($db)) { |
| 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; |