Passed
Push — master ( 5d8af1...e44bd6 )
by Petr
09:24
created

MSSQLTrusting::connectToServer()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 22
ccs 0
cts 15
cp 0
crap 12
rs 9.8666
1
<?php
2
3
namespace kalanis\kw_mapper\Storage\Database\PDO;
4
5
6
use PDO;
7
8
9
/**
10
 * Class MSSQLTrusting
11
 * @package kalanis\kw_mapper\Storage\Database\PDO
12
 * Connection to Microsoft SQL, they based it on TransactSQL
13
 * Can be also used for Sybase DB, because they have similar base
14
 *
15
 * This extension is just to trust automatically to server certificates
16
 * @link https://stackoverflow.com/questions/71688125/odbc-driver-18-for-sql-serverssl-provider-error1416f086#72348333
17
 */
18
class MSSQLTrusting extends MSSQL
19
{
20
    protected function connectToServer(): PDO
21
    {
22
        $connection = new PDO(
23
            sprintf('sqlsrv:server=%s;Database=%s;TrustServerCertificate=yes;',
24
                $this->config->getLocation(),
25
                $this->config->getDatabase()
26
            ),
27
            $this->config->getUser(),
28
            $this->config->getPassword()
29
        );
30
31
        $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
32
33
        if ($this->config->isPersistent()) {
34
            $connection->setAttribute(PDO::ATTR_PERSISTENT, true);
35
        }
36
37
        foreach ($this->attributes as $key => $value){
38
            $connection->setAttribute($key, $value);
39
        }
40
41
        return $connection;
42
    }
43
}
44