Completed
Push — master ( 1b3be6...409e1d )
by Adeola
02:57
created

DataBaseConnection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 20
Bugs 8 Features 4
Metric Value
wmc 4
c 20
b 8
f 4
lcom 1
cbo 1
dl 0
loc 52
ccs 19
cts 19
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A getDataBaseDriver() 0 6 1
A loadEnv() 0 6 2
1
<?php
2
3
/**
4
 * This class is involve in connection to the database.
5
 *
6
 * @author   Raimi Ademola <[email protected]>
7
 * @copyright: 2016 Andela
8
 */
9
namespace Demo;
10
11
use Dotenv\Dotenv;
12
use PDO;
13
14
class DataBaseConnection extends PDO
15
{
16
    public $servername;
17
    public $username;
18
    public $password;
19
    public $driver;
20
    public $dbname;
21
22
    /**
23
     * This is a constructor; a default method  that will be called automatically during class instantiation.
24
     */
25 57
    public function __construct($path = null)
26
    {
27 57
        $this->loadEnv($path);
28
29 57
        $this->servername = getenv('DB_HOST');
30 57
        $this->username = getenv('DB_USERNAME');
31 57
        $this->password = getenv('DB_PASSWORD');
32 57
        $this->driver = getenv('DB_DRIVER');
33 57
        $this->dbname = getenv('DB_NAME');
34
35
        $options = [
0 ignored issues
show
Unused Code introduced by
$options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
36 57
            PDO::ATTR_PERSISTENT => true,
37 38
            PDO::ATTR_ERRMODE    => PDO::ERRMODE_EXCEPTION,
38 38
        ];
39
40
        //parent::__construct($this->getDataBaseDriver(), $this->username, $this->password, $options);
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41 57
    }
42
43
    /**
44
     * This method determines the driver to be used for appropriate database server.
45
     *
46
     *
47
     * @return string dsn
48
     */
49 3
    public function getDataBaseDriver()
50
    {
51 3
        $dns = $this->driver.':host='.$this->servername.';dbname='.$this->dbname;
52
53 3
        return $dns;
54
    }
55
56
    /**
57
     * Load Dotenv to grant getenv() access to environment variables in .env file.
58
     */
59 57
    public function loadEnv($path = null)
60
    {
61 57
        $envPath = $path == null ? __DIR__.'/../../' : $path;
62 57
        $dotenv = new Dotenv($envPath);
63 57
        $dotenv->load();
64 57
    }
65
}
66