Completed
Push — master ( 3e875a...016423 )
by Derek Stephen
02:00
created

AbstractDbAdapter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 111
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
openConnection() 0 1 ?
closeConnection() 0 1 ?
A executeQuery() 0 5 1
A getDatabase() 0 4 1
A getHost() 0 4 1
A getPass() 0 4 1
A getUser() 0 4 1
A isConnected() 0 8 2
A getConnection() 0 8 2
1
<?php
2
3
namespace Bone\Db\Adapter;
4
use Bone\Db\Adapter\DbAdapterInterface;
5
use PDO;
6
7
/**
8
 * Class AbstractDbAdapter
9
 * @package Bone\Db\Adapter
10
 */
11
abstract class AbstractDbAdapter implements DbAdapterInterface
12
{
13
    /**
14
     * @var PDO $connection
15
     */
16
    protected  $connection;
17
    /**
18
     * @var string
19
     */
20
    private   $host;
21
    /**
22
     * @var string
23
     */
24
    private   $database;
25
    /**
26
     * @var string
27
     */
28
    private   $user;
29
30
    /** @var string $pass */
31
    private $pass;
32
33
    /**
34
     * @param $credentials
35
     */
36 6
    public function __construct($credentials)
37 6
    {
38 6
        $this->host = $credentials['host'];
39 6
        $this->database = $credentials['database'];
40 6
        $this->user = $credentials['user'];
41 6
        $this->pass = $credentials['pass'];
42 6
    }
43
44
    /**
45
     * @return mixed
46
     */
47
    abstract public function openConnection();
48
49
    /**
50
     * @return mixed
51
     */
52
    abstract public function closeConnection();
53
54
    /**
55
     * @return bool
56
     */
57 4
    public function isConnected()
58 4
    {
59 4
        if(!$this->connection)
60
        {
61 3
            return false;
62
        }
63 1
        return true;
64
    }
65
66
    /**
67
     * @param $sql
68
     * @return mixed|null
69
     */
70 1
    public function executeQuery($sql)
71 1
    {
72
        // @todo: Implement executeQuery() method.
73 1
        return null;
74
    }
75
76
    /**
77
     * @return PDO
78
     */
79 2
    public function getConnection()
80 2
    {
81 2
        if(!$this->isConnected())
82
        {
83 2
            $this->openConnection();
84
        }
85 2
        return $this->connection;
86
    }
87
88
    /**
89
     * @return string|null
90
     */
91 4
    protected  function getDatabase()
92 4
    {
93 3
        return $this->database;
94
    }
95
96
    /**
97
     * @return string|null
98
     */
99 4
    protected function getHost()
100 4
    {
101 3
        return $this->host;
102
    }
103
104
    /**
105
     * @return string|null
106
     */
107 4
    protected function getPass()
108 4
    {
109 3
        return $this->pass;
110
    }
111
112
    /**
113
     * @return string|null
114
     */
115 4
    protected function getUser()
116 4
    {
117 3
        return $this->user;
118
    }
119
120
121
}
122
123