Test Failed
Pull Request — master (#139)
by Jean-Christophe
14:24
created

AbstractDbWrapper::getNamedStatement()   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
namespace Ubiquity\db\providers;
3
4
/**
5
 * Ubiquity\db\providers$AbstractDbWrapper
6
 * This class is part of Ubiquity
7
 *
8
 * @author jcheron <[email protected]>
9
 * @version 1.0.4
10
 *
11
 */
12
abstract class AbstractDbWrapper {
13
14
	protected $dbInstance;
15
16
	protected $statements;
17
18
	public $quote;
19
20
	abstract public function query(string $sql);
21
22
	abstract public function queryAll(string $sql, int $fetchStyle = null);
23
24
	abstract public function queryColumn(string $sql, int $columnNumber = null);
25
26 69
	abstract public static function getAvailableDrivers();
27 69
28 69
	public function _getStatement(string $sql) {
29 69
		return $this->statements[\md5($sql)] ??= $this->getStatement($sql);
30
	}
31 69
32
	public function prepareNamedStatement(string $name, string $sql) {
33
		return $this->statements[$name] = $this->getStatement($sql);
34
	}
35
36
	public function getNamedStatement(string $name, ?string $sql = null) {
37
		return $this->statements[$name] ??= $this->getStatement($sql);
1 ignored issue
show
Bug introduced by
It seems like $sql can also be of type null; however, parameter $sql of Ubiquity\db\providers\Ab...Wrapper::getStatement() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

37
		return $this->statements[$name] ??= $this->getStatement(/** @scrutinizer ignore-type */ $sql);
Loading history...
38
	}
39
40
	abstract public function getStatement(string $sql);
41
42
	abstract public function connect(string $dbType, $dbName, $serverName, string $port, string $user, string $password, array $options);
43
44
	abstract public function getDSN(string $serverName, string $port, string $dbName, string $dbType = 'mysql');
45
46
	abstract public function execute(string $sql);
47
48
	abstract public function prepareStatement(string $sql);
49
50
	abstract public function executeStatement($statement, array $values = null);
51
52
	abstract public function statementRowCount($statement);
53
54
	abstract public function lastInsertId($name = null);
55
56
	/**
57
	 * Used by DAO
58
	 *
59
	 * @param mixed $statement
60
	 * @param string $parameter
61
	 * @param mixed $value
62
	 */
63
	abstract public function bindValueFromStatement($statement, $parameter, $value);
64
65
	abstract public function fetchColumn($statement, array $values = null, int $columnNumber = null);
66
67
	abstract public function fetchAll($statement, array $values = null, $mode = null);
68
69
	abstract public function fetchOne($statement, array $values = null, $mode = null);
70
71
	abstract public function fetchAllColumn($statement, array $values = null, string $column = null);
72
73
	abstract public function getTablesName();
74
75
	abstract public function beginTransaction();
76
77
	abstract public function commit();
78
79
	abstract public function inTransaction();
80
81
	abstract public function rollBack();
82
83
	abstract public function nestable();
84
85
	abstract public function savePoint($level);
86
87
	abstract public function releasePoint($level);
88
89
	abstract public function rollbackPoint($level);
90
91
	abstract public function ping();
92
93
	abstract public function getPrimaryKeys($tableName);
94
95
	abstract public function getFieldsInfos($tableName);
96
97
	abstract public function getForeignKeys($tableName, $pkName, $dbName = null);
98
99
	abstract public function _optPrepareAndExecute($sql, array $values = null, $one = false);
100
101
	public function _optExecuteAndFetch($statement, array $values = null, $one = false) {}
3 ignored issues
show
Unused Code introduced by
The parameter $statement 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

101
	public function _optExecuteAndFetch(/** @scrutinizer ignore-unused */ $statement, array $values = null, $one = false) {}

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...
Unused Code introduced by
The parameter $values 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

101
	public function _optExecuteAndFetch($statement, /** @scrutinizer ignore-unused */ array $values = null, $one = false) {}

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...
Unused Code introduced by
The parameter $one 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

101
	public function _optExecuteAndFetch($statement, array $values = null, /** @scrutinizer ignore-unused */ $one = false) {}

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...
102
103 29
	abstract public function getRowNum(string $tableName, string $pkName, string $condition): int;
104 29
105 29
	abstract public function groupConcat(string $fields, string $separator): string;
106
107
	public function toStringOperator() {
108
		return '';
109
	}
110
111 2
	public function close() {
112 2
		$this->statements = [];
113
		$this->dbInstance = null;
114
	}
115
116
	/**
117
	 *
118
	 * @return object
119
	 */
120
	public function getDbInstance() {
121
		return $this->dbInstance;
122
	}
123
124
	/**
125
	 *
126
	 * @param object $dbInstance
127
	 */
128
	public function setDbInstance($dbInstance) {
129
		$this->dbInstance = $dbInstance;
130
	}
131
132
	public function quoteValue($value, $type = 2) {
133
		return "'" . \addslashes($value) . "'";
134
	}
135
}