DatabaseDriver::labels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
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