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

PDODriver::createConnection()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.025

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 8
nop 0
dl 0
loc 19
ccs 9
cts 10
cp 0.9
crap 5.025
rs 9.6111
c 0
b 0
f 0
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