Passed
Push — master ( 650305...6d2a34 )
by Aleksandar
08:21
created

MySqlDriver::createPdoInstance()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
/**
3
 * Copyright 2021 Aleksandar Panic
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace ArekX\PQL\Drivers\Pdo\MySql;
19
20
use ArekX\PQL\Drivers\Pdo\PdoDriver;
21
22
class MySqlDriver extends PdoDriver
23
{
24
    public $emulatePrepare;
25
26
    public $charset;
27
28 11
    protected function createPdoInstance(): \PDO
29
    {
30 11
        $instance = new \PDO($this->dsn, $this->username, $this->password, $this->options);
31
32 11
        if ($this->emulatePrepare !== null) {
33 1
            $instance->setAttribute(\PDO::ATTR_EMULATE_PREPARES, $this->emulatePrepare);
34
        }
35
36 11
        if ($this->charset) {
37 1
            $instance->exec('SET NAMES ' . $instance->quote($this->charset));
38
        }
39
40 11
        return $instance;
41
    }
42
43 11
    protected function extendConfigure(array $config)
44
    {
45 11
        $this->emulatePrepare = $config['emulatePrepare'] ?? $this->emulatePrepare;
46 11
        $this->charset = $config['charset'] ?? $this->charset;
47
    }
48
}