Passed
Push — master ( b979f8...3829ec )
by Aleksandar
07:20 queued 11s
created

MySqlDriver::createPdoInstance()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 4
nop 0
dl 0
loc 13
ccs 0
cts 7
cp 0
crap 12
rs 10
c 1
b 0
f 0
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
    protected function createPdoInstance(): \PDO
29
    {
30
        $instance = new \PDO($this->dsn, $this->username, $this->password, $this->options);
31
32
        if ($this->emulatePrepare !== null) {
33
            $instance->setAttribute(\PDO::ATTR_EMULATE_PREPARES, $this->emulatePrepare);
34
        }
35
36
        if ($this->charset) {
37
            $this->pdo->exec('SET NAMES ' . $this->pdo->quote($this->charset));
0 ignored issues
show
Bug introduced by
The method quote() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
            $this->pdo->exec('SET NAMES ' . $this->pdo->/** @scrutinizer ignore-call */ quote($this->charset));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
        }
39
40
        return $instance;
41
    }
42
43
    protected function extendConfigure(array $config)
44
    {
45
        $this->emulatePrepare ??= $config['emulatePrepare'];
46
        $this->charset ??= $config['charset'];
47
    }
48
}