Test Failed
Pull Request — master (#197)
by
unknown
10:13
created

AbstractDbWrapper::quoteValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Ubiquity\db\providers;
4
5
use Ubiquity\exceptions\DBException;
6
7
/**
8
 * Ubiquity\db\providers$AbstractDbWrapper
9
 * This class is part of Ubiquity
10
 *
11
 * @author jcheron <[email protected]>
12
 * @version 1.0.6
13
 *
14
 */
15
abstract class AbstractDbWrapper {
16
	protected $dbInstance;
17
	protected $statements;
18
	protected $operations=[
19
			DbOperations::CREATE_DATABASE=>'CREATE DATABASE {name}',
20
			DbOperations::CREATE_TABLE=>'CREATE TABLE {name} ({fields}) {attributes}',
21
			DbOperations::SELECT_DB=>'USE {name}',
22
			DbOperations::FIELD=>'{name} {type} {extra}',
23
			DbOperations::ALTER_TABLE=>'ALTER TABLE {tableName} {alter}',
24
			DbOperations::FOREIGN_KEY=>'ALTER TABLE {tableName} ADD CONSTRAINT {fkName} FOREIGN KEY ({fkFieldName}) REFERENCES {referencesTableName} ({referencesFieldName}) ON DELETE {onDelete} ON UPDATE {onUpdate}',
25
			DbOperations::ALTER_TABLE_KEY=>'ALTER TABLE {tableName} ADD {type} KEY ({pkFields})',
26
			DbOperations::AUTO_INC=>'ALTER TABLE {tableName} MODIFY {fieldName} AUTO_INCREMENT, AUTO_INCREMENT={value}',
27
			DbOperations::MODIFY_FIELD=>'ALTER TABLE {tableName} MODIFY {fieldName} {attributes}',
28
			DbOperations::ADD_FIELD=>'ALTER TABLE {tableName} ADD {fieldName} {attributes}'
29
	];
30
31
	const PHP_TYPES = [ 'string' => true,'bool' => true,'float' => true,'int' => true ];
32
	
33
	public $quote;
34
35
	abstract public function query(string $sql);
36
37
	abstract public function queryAll(string $sql, int $fetchStyle = null);
38
39
	abstract public function queryColumn(string $sql, int $columnNumber = null);
40
41 138
	abstract public static function getAvailableDrivers();
42 138
43
	public function _getStatement(string $sql) {
44
		return $this->statements [\md5 ( $sql )] ??= $this->getStatement ( $sql );
45
	}
46
47
	public function prepareNamedStatement(string $name, string $sql) {
48
		return $this->statements [$name] = $this->getStatement ( $sql );
49
	}
50
51
	public function getNamedStatement(string $name, ?string $sql = null) {
52
		return $this->statements [$name] ??= $this->getStatement ( $sql );
53
	}
54
55
	abstract public function getStatement(string $sql);
56
57
	abstract public function connect(string $dbType, $dbName, $serverName, string $port, string $user, string $password, array $options);
58
59
	abstract public function getDSN(string $serverName, string $port, string $dbName, string $dbType = 'mysql');
60
61
	abstract public function execute(string $sql);
62
63
	abstract public function prepareStatement(string $sql);
64
65
	abstract public function executeStatement($statement, array $values = null);
66
67
	abstract public function statementRowCount($statement);
68
69
	abstract public function lastInsertId($name = null);
70
71
	/**
72
	 * Used by DAO
73
	 *
74
	 * @param mixed $statement
75
	 * @param string $parameter
76
	 * @param mixed $value
77
	 */
78
	abstract public function bindValueFromStatement($statement, $parameter, $value);
79
80
	abstract public function fetchColumn($statement, array $values = null, int $columnNumber = null);
81
82
	abstract public function fetchAll($statement, array $values = null, $mode = null);
83
84
	abstract public function fetchOne($statement, array $values = null, $mode = null);
85
86
	abstract public function fetchAllColumn($statement, array $values = null, string $column = null);
87
88
	abstract public function getTablesName();
89
90
	abstract public function beginTransaction();
91
92
	abstract public function commit();
93
94
	abstract public function inTransaction();
95
96
	abstract public function rollBack();
97
98
	abstract public function nestable();
99
100
	abstract public function savePoint($level);
101
102
	abstract public function releasePoint($level);
103
104
	abstract public function rollbackPoint($level);
105
106
	abstract public function ping();
107
108
	abstract public function getPrimaryKeys($tableName);
109
110
	abstract public function getFieldsInfos($tableName);
111
112
	abstract public function getForeignKeys($tableName, $pkName, $dbName = null);
113
114
	abstract public function _optPrepareAndExecute($sql, array $values = null, $one = false);
115
116
	public function _optExecuteAndFetch($statement, array $values = null, $one = false) {
117
	}
118
119
	abstract public function getRowNum(string $tableName, string $pkName, string $condition): int;
120
121
	abstract public function groupConcat(string $fields, string $separator): string;
122
123
	public function toStringOperator() {
124
		return '';
125 102
	}
126 102
127 102
	public function close() {
128
		$this->statements = [ ];
129
		$this->dbInstance = null;
130
	}
131
132
	/**
133
	 *
134 4
	 * @return object
135 4
	 */
136
	public function getDbInstance() {
137
		return $this->dbInstance;
138
	}
139
140
	/**
141
	 *
142
	 * @param object $dbInstance
143
	 */
144
	public function setDbInstance($dbInstance) {
145
		$this->dbInstance = $dbInstance;
146
	}
147
148
	public function quoteValue($value, $type = 2) {
149
		return "'" . \addslashes ( $value ) . "'";
150
	}
151
152
	/**
153
	 * 
154
	 * @param string $dbType
155
	 * @return string
156
	 * 
157
	 * @deprecated use Database::getPHPType instead
158
	 */
159
	public function getPHPType(string $dbType): string {
160
		return '';
161
	}
162
	
163
	/**
164
	 * Returns the SQL string for a migration operation.
165
	 * @param string $operation
166 1
	 * @return string
167 1
	 */
168
	public function migrateOperation(string $operation):?string{
169
		return $this->operations[$operation]??null;
170
	}
171
172
	/**
173
	 * @param $isolationLevel
174
	 * @throws DBException
175
	 * @return mixed
176
	 */
177
	public function setIsolationLevel($isolationLevel){
1 ignored issue
show
Unused Code introduced by
The parameter $isolationLevel is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

177
	public function setIsolationLevel(/** @scrutinizer ignore-unused */ $isolationLevel){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
178
		throw new DBException('The setIsolation level is not implemented for this wrapper');
179
	}
180
}