Passed
Push — master ( 10aa22...f23c21 )
by Morris
13:04 queued 10s
created

OC_DB_StatementWrapper::closeCursor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Bart Visscher <[email protected]>
7
 * @author Christoph Wurst <[email protected]>
8
 * @author Jörn Friedrich Dreyer <[email protected]>
9
 * @author Lukas Reschke <[email protected]>
10
 * @author Morris Jobke <[email protected]>
11
 * @author Piotr Mrówczyński <[email protected]>
12
 * @author Robin Appelman <[email protected]>
13
 * @author Thomas Müller <[email protected]>
14
 *
15
 * @license AGPL-3.0
16
 *
17
 * This code is free software: you can redistribute it and/or modify
18
 * it under the terms of the GNU Affero General Public License, version 3,
19
 * as published by the Free Software Foundation.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License, version 3,
27
 * along with this program. If not, see <http://www.gnu.org/licenses/>
28
 *
29
 */
30
31
/**
32
 * small wrapper around \Doctrine\DBAL\Driver\Statement to make it behave, more like an MDB2 Statement
33
 *
34
 * @method boolean bindValue(mixed $param, mixed $value, integer $type = null);
35
 * @method string errorCode();
36
 * @method array errorInfo();
37
 * @method integer rowCount();
38
 * @method array fetchAll(integer $fetchMode = null);
39
 */
40
class OC_DB_StatementWrapper {
41
	/**
42
	 * @var \Doctrine\DBAL\Driver\Statement
43
	 */
44
	private $statement = null;
45
	private $isManipulation = false;
46
	private $lastArguments = [];
47
48
	/**
49
	 * @param boolean $isManipulation
50
	 */
51
	public function __construct($statement, $isManipulation) {
52
		$this->statement = $statement;
53
		$this->isManipulation = $isManipulation;
54
	}
55
56
	/**
57
	 * pass all other function directly to the \Doctrine\DBAL\Driver\Statement
58
	 */
59
	public function __call($name,$arguments) {
60
		return call_user_func_array([$this->statement,$name], $arguments);
61
	}
62
63
	/**
64
	 * make execute return the result instead of a bool
65
	 *
66
	 * @param array $input
67
	 * @return \OC_DB_StatementWrapper|int|bool
68
	 */
69
	public function execute($input = []) {
70
		$this->lastArguments = $input;
71
		if (count($input) > 0) {
72
			$result = $this->statement->execute($input);
73
		} else {
74
			$result = $this->statement->execute();
75
		}
76
77
		if ($result === false) {
78
			return false;
79
		}
80
		if ($this->isManipulation) {
81
			return $this->statement->rowCount();
82
		} else {
83
			return $this;
84
		}
85
	}
86
87
	/**
88
	 * provide an alias for fetch
89
	 *
90
	 * @return mixed
91
	 */
92
	public function fetchRow() {
93
		return $this->statement->fetch();
94
	}
95
96
	/**
97
	 * Provide a simple fetchOne.
98
	 *
99
	 * fetch single column from the next row
100
	 * @param int $column the column number to fetch
101
	 * @return string
102
	 */
103
	public function fetchOne($column = 0) {
104
		return $this->statement->fetchColumn($column);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->statement->fetchColumn($column) could also return false which is incompatible with the documented return type string. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
105
	}
106
107
	/**
108
	 * Closes the cursor, enabling the statement to be executed again.
109
	 *
110
	 * @deprecated Use Result::free() instead.
111
	 */
112
	public function closeCursor(): void {
113
		$this->statement->closeCursor();
114
	}
115
116
	/**
117
	 * Binds a PHP variable to a corresponding named or question mark placeholder in the
118
	 * SQL statement that was use to prepare the statement.
119
	 *
120
	 * @param mixed $column Either the placeholder name or the 1-indexed placeholder index
121
	 * @param mixed $variable The variable to bind
122
	 * @param integer|null $type one of the  PDO::PARAM_* constants
123
	 * @param integer|null $length max length when using an OUT bind
124
	 * @return boolean
125
	 */
126
	public function bindParam($column, &$variable, $type = null, $length = null) {
127
		return $this->statement->bindParam($column, $variable, $type, $length);
128
	}
129
}
130