Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
28 / 28 |
|
100.00% |
13 / 13 |
|
100.00% |
13 / 13 |
|
100.00% |
14 / 14 |
CRAP | |
100.00% |
1 / 1 |
| Connection | |
100.00% |
28 / 28 |
|
100.00% |
13 / 13 |
|
100.00% |
13 / 13 |
|
100.00% |
14 / 14 |
14 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| credentials | |
100.00% |
2 / 2 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
100.00% |
1 / 1 |
1 | |||||
| options | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| option | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fetch | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| pingAfterIdle | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| maxConnectionAge | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| placeholders | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| migrationTable | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| migrationColumns | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| migrations | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| addMigration | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| migrationNamespace | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| addSql | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celema\Quma; |
| 6 | |
| 7 | /** |
| 8 | * @api |
| 9 | * |
| 10 | * @psalm-import-type SqlConfig from Config |
| 11 | * @psalm-import-type PlaceholderConfig from Config |
| 12 | */ |
| 13 | class Connection |
| 14 | { |
| 15 | public readonly Config $config; |
| 16 | |
| 17 | /** @psalm-param SqlConfig $sql */ |
| 18 | public function __construct(string $dsn, string|array $sql) |
| 19 | { |
| 20 | $this->config = new Config($dsn, $sql); |
| 21 | } |
| 22 | |
| 23 | public function credentials( |
| 24 | string $username, |
| 25 | #[\SensitiveParameter] |
| 26 | ?string $password = null, |
| 27 | ): static { |
| 28 | $this->config->setCredentials($username, $password); |
| 29 | |
| 30 | return $this; |
| 31 | } |
| 32 | |
| 33 | /** @param array<array-key, mixed> $options */ |
| 34 | public function options(array $options): static |
| 35 | { |
| 36 | $this->config->setPdoOptions($options); |
| 37 | |
| 38 | return $this; |
| 39 | } |
| 40 | |
| 41 | public function option(int $attribute, mixed $value): static |
| 42 | { |
| 43 | $this->config->setPdoOption($attribute, $value); |
| 44 | |
| 45 | return $this; |
| 46 | } |
| 47 | |
| 48 | public function fetch(int $fetchMode): static |
| 49 | { |
| 50 | $this->config->setFetchMode($fetchMode); |
| 51 | |
| 52 | return $this; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Before a connection that was idle for at least this many seconds is |
| 57 | * used again, it is pinged and replaced if it is broken. 0 disables the |
| 58 | * check. Default: 60. |
| 59 | */ |
| 60 | public function pingAfterIdle(int $seconds): static |
| 61 | { |
| 62 | $this->config->setPingAfterIdle($seconds); |
| 63 | |
| 64 | return $this; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * A connection older than this many seconds is replaced before it is |
| 69 | * used again. 0 keeps connections regardless of their age (default). |
| 70 | */ |
| 71 | public function maxConnectionAge(int $seconds): static |
| 72 | { |
| 73 | $this->config->setMaxConnectionAge($seconds); |
| 74 | |
| 75 | return $this; |
| 76 | } |
| 77 | |
| 78 | /** @psalm-param PlaceholderConfig $placeholders */ |
| 79 | public function placeholders(Delimiters $delimiters, array $placeholders): static |
| 80 | { |
| 81 | $this->config->setPlaceholders($delimiters, $placeholders); |
| 82 | |
| 83 | return $this; |
| 84 | } |
| 85 | |
| 86 | public function migrationTable(string $table): static |
| 87 | { |
| 88 | $this->config->setMigrationsTable($table); |
| 89 | |
| 90 | return $this; |
| 91 | } |
| 92 | |
| 93 | public function migrationColumns(string $migration, string $applied = 'applied'): static |
| 94 | { |
| 95 | $this->config->setMigrationsColumnMigration($migration); |
| 96 | $this->config->setMigrationsColumnApplied($applied); |
| 97 | |
| 98 | return $this; |
| 99 | } |
| 100 | |
| 101 | /** @psalm-param SqlConfig $migrations */ |
| 102 | public function migrations(array|string $migrations): static |
| 103 | { |
| 104 | $this->config->setMigrations($migrations); |
| 105 | |
| 106 | return $this; |
| 107 | } |
| 108 | |
| 109 | /** @param non-empty-string $migrations */ |
| 110 | public function addMigration(string $migrations): static |
| 111 | { |
| 112 | $this->config->addMigrationDir($migrations); |
| 113 | |
| 114 | return $this; |
| 115 | } |
| 116 | |
| 117 | /** @psalm-param SqlConfig $dirs */ |
| 118 | public function migrationNamespace(string $namespace, string|array $dirs): static |
| 119 | { |
| 120 | $this->config->setMigrationNamespace($namespace, $dirs); |
| 121 | |
| 122 | return $this; |
| 123 | } |
| 124 | |
| 125 | /** @psalm-param SqlConfig $sql */ |
| 126 | public function addSql(array|string $sql): static |
| 127 | { |
| 128 | $this->config->addSqlDirs($sql); |
| 129 | |
| 130 | return $this; |
| 131 | } |
| 132 | } |