Passed
Push — dbal ( 23f922...9cad68 )
by Greg
15:01
created

MySQLDriver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A collationUTF8() 0 15 4
A collationASCII() 0 3 1
A __construct() 0 2 1
A connect() 0 5 1
1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2023 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\DB\Drivers;
21
22
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
23
use Doctrine\DBAL\Driver\PDO\Connection;
24
use Fisharebest\Webtrees\DB;
25
use PDO;
26
use SensitiveParameter;
1 ignored issue
show
Bug introduced by
The type SensitiveParameter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
28
use function version_compare;
29
30
/**
31
 * Driver for MySQL
32
 */
33
class MySQLDriver extends AbstractMySQLDriver implements DriverInterface
34
{
35
    use DriverTrait;
36
37
    public function __construct(private readonly PDO $pdo)
38
    {
39
    }
40
41
    public function connect(
42
        #[SensitiveParameter]
43
        array $params,
44
    ): Connection {
45
        return new Connection($this->pdo);
46
    }
47
48
    public function collationASCII(): string
49
    {
50
        return 'ascii_bin';
51
    }
52
53
    public function collationUTF8(): string
54
    {
55
        $version = DB::connection()->getServerVersion();
56
57
        // MySQL
58
        if (version_compare($version, '5.7.7') >= 0 && version_compare($version, '10.0.0') < 0) {
59
            return 'utf8mb4_unicode_ci';
60
        }
61
62
        // MariaDB
63
        if (version_compare($version, '10.2.4') >= 0) {
64
            return 'utf8mb4_unicode_ci';
65
        }
66
67
        return 'utf8mb3_unicode_ci';
68
    }
69
}
70