DatabaseDriver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
c 1
b 0
f 1
dl 0
loc 53
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A dsnName() 0 5 1
A isMysqlFamily() 0 3 2
A label() 0 7 1
A labels() 0 3 1
1
<?php
2
3
namespace Silviooosilva\CacheerPhp\Enums;
4
5
enum DatabaseDriver: string
6
{
7
    case MYSQL = 'mysql';
8
    case MARIADB = 'mariadb';
9
    case SQLITE = 'sqlite';
10
    case PGSQL = 'pgsql';
11
12
    /**
13
     * Human friendly label for error/help messages.
14
     * 
15
     * @return string
16
     */
17
    public function label(): string
18
    {
19
        return match ($this) {
20
            self::MYSQL => 'MySQL(mysql)',
21
            self::MARIADB => 'MariaDB(mariadb)',
22
            self::SQLITE => 'SQLite(sqlite)',
23
            self::PGSQL => 'PgSQL(pgsql)',
24
        };
25
    }
26
27
    /**
28
     * PDO DSN identifier for the driver.
29
     * 
30
     * @return string
31
     */
32
    public function dsnName(): string
33
    {
34
        return match ($this) {
35
            self::MARIADB => self::MYSQL->value,
36
            default => $this->value,
37
        };
38
    }
39
40
    /**
41
     * Whether the driver behaves like MySQL for SQL syntax decisions.
42
     * 
43
     * @return bool
44
     */
45
    public function isMysqlFamily(): bool
46
    {
47
        return $this === self::MYSQL || $this === self::MARIADB;
48
    }
49
50
    /**
51
     * Handy helper for building allow-list messages.
52
     *
53
     * @return array<int, string>
54
     */
55
    public static function labels(): array
56
    {
57
        return array_map(static fn (self $driver) => $driver->label(), self::cases());
58
    }
59
}
60
61