DB   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 7 2
A __construct() 0 24 1
1
<?php
2
/**
3
 * The database file.
4
 *
5
 * @link       https://github.com/maab16
6
 * @since      1.0.0
7
 */
8
9
namespace WPB\Database;
10
11
use Illuminate\Database\Capsule\Manager as Capsule;
12
13
/**
14
 * The Database class.
15
 *
16
 * @since      1.0.0
17
 *
18
 * @author     Md Abu Ahsan basir <[email protected]>
19
 */
20
class DB extends Capsule
21
{
22
    /**
23
     * The database instance.
24
     *
25
     * @since    1.0.0
26
     *
27
     * @var \WPB\Database\DB The database instance.
28
     */
29
    protected static $instance = false;
30
31
    /**
32
     * Return database instance.
33
     *
34
     * @since    1.0.0
35
     *
36
     * @return null|\WPB\Database\DB
37
     */
38
    public static function instance()
39
    {
40
        if (!static::$instance) {
41
            static::$instance = new self();
42
        }
43
44
        return static::$instance;
45
    }
46
47
    /**
48
     * The database constructor.
49
     *
50
     * @since    1.0.0
51
     *
52
     * @return void
53
     */
54
    public function __construct()
55
    {
56
        parent::__construct();
57
58
        global $wpdb;
59
60
        $this->addConnection(
61
            [
62
63
                'driver'    => 'mysql',
64
                'host'      => $wpdb->dbhost,
65
                'database'  => $wpdb->dbname,
66
                'username'  => $wpdb->dbuser,
67
                'password'  => $wpdb->dbpassword,
68
                'prefix'    => $wpdb->prefix,
69
                'charset'   => $wpdb->charset,
70
                'collation' => $wpdb->collate,
71
            ]
72
        );
73
74
        // Make this Capsule instance available globally.
75
        $this->setAsGlobal();
76
        // Setup the Eloquent ORM.
77
        $this->bootEloquent();
78
    }
79
}
80