DbConnection::setPassword()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Base connection class
4
 *
5
 * @file      DbConnection.php
6
 *
7
 * PHP version 8.0+
8
 *
9
 * @author    Alexander Yancharuk <alex at itvault dot info>
10
 * @copyright © 2012-2021 Alexander Yancharuk
11
 * @date      2013-12-31 15:44
12
 * @license   The BSD 3-Clause License
13
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
14
 */
15
16
namespace Veles\DataBase\Connections;
17
18
use Exception;
19
use Traits\DriverInterface;
20
use Veles\Traits\Driver;
21
22
/**
23
 * Class DbConnection
24
 *
25
 * Базовый класс-контейнер для хранения общих для всех соединений параметров
26
 *
27
 * @author  Alexander Yancharuk <alex at itvault dot info>
28
 */
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)
120
	{
121 3
		$this->user_name = $user_name;
122 3
		return $this;
123
	}
124
}
125