Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
94.44% covered (success)
94.44%
17 / 18
50.00% covered (danger)
50.00%
7 / 14
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
DriverPolicy
100.00% covered (success)
100.00%
16 / 16
94.44% covered (success)
94.44%
17 / 18
50.00% covered (danger)
50.00%
7 / 14
100.00% covered (success)
100.00%
4 / 4
22.50
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
 isKnown
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
 supportsTransactions
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
75.00% covered (warning)
75.00%
3 / 4
100.00% covered (success)
100.00%
1 / 1
4.25
 supportsMigration
100.00% covered (success)
100.00%
9 / 9
90.91% covered (success)
90.91%
10 / 11
25.00% covered (danger)
25.00%
2 / 8
100.00% covered (success)
100.00%
1 / 1
10.75
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Quma\Migrations;
6
7use RuntimeException;
8
9final 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}