Passed
Push — master ( d71ac2...6fd222 )
by Wilmer
03:39
created

PDODriver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 26
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDriverName() 0 3 1
A createConnection() 0 19 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mysql;
6
7
use PDO;
8
use Yiisoft\Db\Driver\PDO\AbstractPDODriver;
9
10
final class PDODriver extends AbstractPDODriver
11
{
12 280
    public function createConnection(): PDO
13
    {
14 280
        $this->attributes += [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
15
16 280
        if (PHP_VERSION_ID >= 80100) {
17
            $this->attributes += [PDO::ATTR_STRINGIFY_FETCHES => true];
18
        }
19
20 280
        $pdo = parent::createConnection();
21
22 280
        if ($this->charset !== null) {
23 1
            $pdo->exec('SET NAMES ' . $pdo->quote($this->charset));
24
        }
25
26 280
        if (!str_contains($this->dsn, 'charset') && $this->charset === null) {
27 1
            $pdo->exec('SET NAMES ' . $pdo->quote('utf8mb4'));
28
        }
29
30 280
        return $pdo;
31
    }
32
33 374
    public function getDriverName(): string
34
    {
35 374
        return 'mysql';
36
    }
37
}
38