Connection::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This class provide the pdo connection object.
4
 *
5
 * @author RN Kushwaha <[email protected]>
6
 *
7
 * @since v0.0.2 <Date: 29th April, 2019>
8
 */
9
10
namespace Dolphin\Connections;
11
12
use App\Config\Credentials;
13
14
class Connection
15
{
16
    private static $con = null;
17
18
    private function __construct()
19
    {
20
    }
21
22
    public static function getPrefix()
23
    {
24
        return Credentials::get('prefix');
0 ignored issues
show
Bug introduced by
The method get() does not exist on App\Config\Credentials. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

24
        return Credentials::/** @scrutinizer ignore-call */ get('prefix');
Loading history...
25
    }
26
27
    public static function get()
28
    {
29
        if (!self::$con) {
30
            self::$con = new \PDO('mysql:host=localhost; dbname='.Credentials::get('database'),
31
                                    Credentials::get('username'),
32
                                    Credentials::get('password')
33
                                );
34
            self::$con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
35
            // which tells PDO to disable emulated prepared statements and use real prepared statements.
36
            // This makes sure the statement and the values aren't parsed by PHP before sending it to the
37
            // MySQL server (giving a possible attacker no chance to inject malicious SQL).
38
            self::$con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
39
        }
40
41
        return self::$con;
42
    }
43
44
    private function __clone()
45
    {
46
    }
47
}
48