Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
16 / 16 |
|
94.44% |
17 / 18 |
|
50.00% |
7 / 14 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| DriverPolicy | |
100.00% |
16 / 16 |
|
94.44% |
17 / 18 |
|
50.00% |
7 / 14 |
|
100.00% |
4 / 4 |
22.50 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isKnown | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| supportsTransactions | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
|
75.00% |
3 / 4 |
|
100.00% |
1 / 1 |
4.25 | |||
| supportsMigration | |
100.00% |
9 / 9 |
|
90.91% |
10 / 11 |
|
25.00% |
2 / 8 |
|
100.00% |
1 / 1 |
10.75 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Quma\Migrations; |
| 6 | |
| 7 | use RuntimeException; |
| 8 | |
| 9 | final readonly class DriverPolicy |
| 10 | { |
| 11 | private const array KNOWN_DRIVERS = ['sqlite', 'mysql', 'pgsql']; |
| 12 | |
| 13 | public function __construct( |
| 14 | private string $driver, |
| 15 | ) {} |
| 16 | |
| 17 | public function isKnown(): bool |
| 18 | { |
| 19 | return in_array($this->driver, self::KNOWN_DRIVERS, strict: true); |
| 20 | } |
| 21 | |
| 22 | public function supportsTransactions(): bool |
| 23 | { |
| 24 | return match ($this->driver) { |
| 25 | 'sqlite', 'pgsql' => true, |
| 26 | 'mysql' => false, |
| 27 | default => throw new RuntimeException('Database driver not supported'), |
| 28 | }; |
| 29 | } |
| 30 | |
| 31 | public function supportsMigration(string $migration): bool |
| 32 | { |
| 33 | $file = basename($migration); |
| 34 | $scoped = false; |
| 35 | |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 39 | } |
| 40 | |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | $scoped = true; |
| 46 | } |
| 47 | |
| 48 | return !$scoped; |
| 49 | } |
| 50 | } |
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 string $driver, |
| 15 | ) {} |
| 19 | return in_array($this->driver, self::KNOWN_DRIVERS, strict: true); |
| 20 | } |
| 31 | public function supportsMigration(string $migration): bool |
| 32 | { |
| 33 | $file = basename($migration); |
| 34 | $scoped = false; |
| 35 | |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 39 | } |
| 40 | |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | $scoped = true; |
| 46 | } |
| 47 | |
| 48 | return !$scoped; |
| 49 | } |
| 31 | public function supportsMigration(string $migration): bool |
| 32 | { |
| 33 | $file = basename($migration); |
| 34 | $scoped = false; |
| 35 | |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 31 | public function supportsMigration(string $migration): bool |
| 32 | { |
| 33 | $file = basename($migration); |
| 34 | $scoped = false; |
| 35 | |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 41 | if ($driver === $this->driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 39 | } |
| 40 | |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | $scoped = true; |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 39 | } |
| 40 | |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | $scoped = true; |
| 46 | } |
| 47 | |
| 48 | return !$scoped; |
| 49 | } |
| 31 | public function supportsMigration(string $migration): bool |
| 32 | { |
| 33 | $file = basename($migration); |
| 34 | $scoped = false; |
| 35 | |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 39 | } |
| 40 | |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | $scoped = true; |
| 46 | } |
| 47 | |
| 48 | return !$scoped; |
| 49 | } |
| 31 | public function supportsMigration(string $migration): bool |
| 32 | { |
| 33 | $file = basename($migration); |
| 34 | $scoped = false; |
| 35 | |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 31 | public function supportsMigration(string $migration): bool |
| 32 | { |
| 33 | $file = basename($migration); |
| 34 | $scoped = false; |
| 35 | |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 41 | if ($driver === $this->driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 39 | } |
| 40 | |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | $scoped = true; |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 39 | } |
| 40 | |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | $scoped = true; |
| 46 | } |
| 47 | |
| 48 | return !$scoped; |
| 49 | } |
| 31 | public function supportsMigration(string $migration): bool |
| 32 | { |
| 33 | $file = basename($migration); |
| 34 | $scoped = false; |
| 35 | |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 39 | } |
| 40 | |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | $scoped = true; |
| 46 | } |
| 47 | |
| 48 | return !$scoped; |
| 49 | } |
| 31 | public function supportsMigration(string $migration): bool |
| 32 | { |
| 33 | $file = basename($migration); |
| 34 | $scoped = false; |
| 35 | |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 36 | foreach (self::KNOWN_DRIVERS as $driver) { |
| 37 | if (!str_contains($file, "[{$driver}]")) { |
| 38 | continue; |
| 39 | } |
| 40 | |
| 41 | if ($driver === $this->driver) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | $scoped = true; |
| 46 | } |
| 47 | |
| 48 | return !$scoped; |
| 49 | } |
| 24 | return match ($this->driver) { |
| 25 | 'sqlite', 'pgsql' => true, |
| 27 | default => throw new RuntimeException('Database driver not supported'), |
| 28 | }; |
| 29 | } |
| 24 | return match ($this->driver) { |
| 25 | 'sqlite', 'pgsql' => true, |
| 27 | default => throw new RuntimeException('Database driver not supported'), |
| 28 | }; |
| 29 | } |
| 24 | return match ($this->driver) { |
| 26 | 'mysql' => false, |
| 27 | default => throw new RuntimeException('Database driver not supported'), |
| 28 | }; |
| 29 | } |
| 24 | return match ($this->driver) { |
| 27 | default => throw new RuntimeException('Database driver not supported'), |