DB::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 24
ccs 0
cts 15
cp 0
crap 2
rs 9.536
c 0
b 0
f 0
1
<?php
2
3
namespace CodexShaper\WP\Database;
4
5
use Illuminate\Database\Capsule\Manager as Capsule;
6
7
class DB extends Capsule
8
{
9
    protected static $instance = false;
10
11
    public static function instance()
12
    {
13
        if (!static::$instance) {
14
            static::$instance = new self();
0 ignored issues
show
Documentation Bug introduced by
It seems like new self() of type object<CodexShaper\WP\Database\DB> is incompatible with the declared type boolean of property $instance.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
15
        }
16
17
        return static::$instance;
18
    }
19
20
    public function __construct()
21
    {
22
        parent::__construct();
23
24
        global $wpdb;
25
26
        $this->addConnection([
27
28
            'driver' 		    => 'mysql',
29
            'host' 			     => $wpdb->dbhost,
30
            'database' 		  => $wpdb->dbname,
31
            'username' 		  => $wpdb->dbuser,
32
            'password' 		  => $wpdb->dbpassword,
33
            'prefix'   		  => $wpdb->prefix,
34
            'charset'   		 => $wpdb->charset,
35
            'collation'   	=> $wpdb->collate,
36
        ]);
37
38
        //Make this Capsule instance available globally.
39
        $this->setAsGlobal();
40
41
        // Setup the Eloquent ORM.
42
        $this->bootEloquent();
43
    }
44
}
45