Passed
Push — better-naming-classes ( 1280e4...dce7bb )
by Wilmer
03:43
created

Driver::createConnection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Pgsql;
6
7
use PDO;
8
use Yiisoft\Db\Driver\PDO\AbstractPDODriver;
9
10
/**
11
 * Implements the PostgreSQL Server driver based on the PDO (PHP Data Objects) extension.
12
 *
13
 * @link https://www.php.net/manual/en/ref.pdo-pgsql.php
14
 */
15
final class Driver extends AbstractPDODriver
16
{
17 291
    public function createConnection(): PDO
18
    {
19 291
        $this->attributes += [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
20 291
        $pdo = parent::createConnection();
21
22 291
        if ($this->charset !== null) {
23 290
            $pdo->exec('SET NAMES ' . $pdo->quote($this->charset));
24
        }
25
26 291
        return $pdo;
27
    }
28
29 415
    public function getDriverName(): string
30
    {
31 415
        return 'pgsql';
32
    }
33
}
34