| Total Complexity | 9 |
| Total Lines | 94 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | abstract class DbConnection implements DriverInterface |
||
| 30 | { |
||
| 31 | /** @var string */ |
||
| 32 | protected $user_name; |
||
| 33 | /** @var string */ |
||
| 34 | protected $password; |
||
| 35 | /** @var string */ |
||
| 36 | protected $name; |
||
| 37 | /** @var mixed */ |
||
| 38 | protected $resource; |
||
| 39 | |||
| 40 | use Driver; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param string $name Unique connection name |
||
| 44 | */ |
||
| 45 | 39 | public function __construct($name) |
|
| 46 | { |
||
| 47 | 39 | $this->name = $name; |
|
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Connection create |
||
| 52 | * |
||
| 53 | * Must be realized in child classes |
||
| 54 | * |
||
| 55 | * @return mixed |
||
| 56 | */ |
||
| 57 | abstract public function create(); |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return mixed |
||
| 61 | */ |
||
| 62 | 2 | public function getResource() |
|
| 63 | { |
||
| 64 | 2 | if (null === $this->resource) { |
|
| 65 | 1 | $this->create(); |
|
| 66 | } |
||
| 67 | |||
| 68 | 2 | return $this->resource; |
|
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param mixed $resource |
||
| 73 | */ |
||
| 74 | 1 | public function setResource($resource) |
|
| 75 | { |
||
| 76 | 1 | $this->resource = $resource; |
|
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | 5 | public function getName() |
|
| 83 | { |
||
| 84 | 5 | return $this->name; |
|
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @throws Exception |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | 3 | public function getPassword() |
|
| 92 | { |
||
| 93 | 3 | return $this->password; |
|
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @param string $password |
||
| 98 | * @return $this |
||
| 99 | */ |
||
| 100 | 3 | public function setPassword($password) |
|
| 101 | { |
||
| 102 | 3 | $this->password = $password; |
|
| 103 | 3 | return $this; |
|
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @throws Exception |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | 3 | public function getUserName() |
|
| 111 | { |
||
| 112 | 3 | return $this->user_name; |
|
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @param string $user_name |
||
| 117 | * @return $this |
||
| 118 | */ |
||
| 119 | 3 | public function setUserName($user_name) |
|
| 123 | } |
||
| 124 | } |
||
| 125 |