Skip to content

Commit cb8bf18

Browse files
committed
Merge pull request #3486 from morozov/conn-stmt-void
Converted Connection and Statement methods which returned false in case of a failure into void
2 parents 1a98457 + 6a689a3 commit cb8bf18

21 files changed

+205
-243
lines changed

UPGRADE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK `Statement` and `Connection` methods return `void`.
4+
5+
`Connection::connect()`, `Statement::bindParam()`, `::bindValue()`, `::execute()`, `ResultStatement::setFetchMode()` and `::closeCursor()` no longer return a boolean value. They will throw an exception in case of failure.
6+
37
## BC BREAK `Statement::rowCount()` is moved.
48

59
`Statement::rowCount()` has been moved to the `ResultStatement` interface where it belongs by definition.

lib/Doctrine/DBAL/Cache/ArrayStatement.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(array $data)
4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function closeCursor()
47+
public function closeCursor() : void
4848
{
4949
unset($this->data);
5050
}
@@ -72,15 +72,13 @@ public function rowCount() : int
7272
/**
7373
* {@inheritdoc}
7474
*/
75-
public function setFetchMode($fetchMode, ...$args)
75+
public function setFetchMode($fetchMode, ...$args) : void
7676
{
7777
if (count($args) > 0) {
7878
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode()');
7979
}
8080

8181
$this->defaultFetchMode = $fetchMode;
82-
83-
return true;
8482
}
8583

8684
/**

lib/Doctrine/DBAL/Cache/ResultCacheStatement.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ public function __construct(ResultStatement $stmt, Cache $resultCache, $cacheKey
7575
/**
7676
* {@inheritdoc}
7777
*/
78-
public function closeCursor()
78+
public function closeCursor() : void
7979
{
8080
$this->statement->closeCursor();
81+
8182
if (! $this->emptied || $this->data === null) {
82-
return true;
83+
return;
8384
}
8485

8586
$data = $this->resultCache->fetch($this->cacheKey);
@@ -90,8 +91,6 @@ public function closeCursor()
9091

9192
$this->resultCache->save($this->cacheKey, $data, $this->lifetime);
9293
unset($this->data);
93-
94-
return true;
9594
}
9695

9796
/**
@@ -105,11 +104,9 @@ public function columnCount()
105104
/**
106105
* {@inheritdoc}
107106
*/
108-
public function setFetchMode($fetchMode, ...$args)
107+
public function setFetchMode($fetchMode, ...$args) : void
109108
{
110109
$this->defaultFetchMode = $fetchMode;
111-
112-
return true;
113110
}
114111

115112
/**

lib/Doctrine/DBAL/Connection.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,12 @@ public function getExpressionBuilder()
339339
/**
340340
* Establishes the connection with the database.
341341
*
342-
* @return bool TRUE if the connection was successfully established, FALSE if
343-
* the connection is already open.
342+
* @throws DriverException
344343
*/
345-
public function connect()
344+
public function connect() : void
346345
{
347346
if ($this->isConnected) {
348-
return false;
347+
return;
349348
}
350349

351350
$driverOptions = $this->params['driverOptions'] ?? [];
@@ -359,12 +358,12 @@ public function connect()
359358
$this->beginTransaction();
360359
}
361360

362-
if ($this->_eventManager->hasListeners(Events::postConnect)) {
363-
$eventArgs = new Event\ConnectionEventArgs($this);
364-
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
361+
if (! $this->_eventManager->hasListeners(Events::postConnect)) {
362+
return;
365363
}
366364

367-
return true;
365+
$eventArgs = new Event\ConnectionEventArgs($this);
366+
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
368367
}
369368

370369
/**
@@ -518,10 +517,8 @@ public function setAutoCommit(bool $autoCommit) : void
518517
* Sets the fetch mode.
519518
*
520519
* @param int $fetchMode
521-
*
522-
* @return void
523520
*/
524-
public function setFetchMode($fetchMode)
521+
public function setFetchMode($fetchMode) : void
525522
{
526523
$this->defaultFetchMode = $fetchMode;
527524
}

lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function isConnectedToMaster()
123123
/**
124124
* {@inheritDoc}
125125
*/
126-
public function connect($connectionName = null)
126+
public function connect($connectionName = null) : void
127127
{
128128
$requestedConnectionChange = ($connectionName !== null);
129129
$connectionName = $connectionName ?: 'slave';
@@ -136,7 +136,7 @@ public function connect($connectionName = null)
136136
// change request, then abort right here, because we are already done.
137137
// This prevents writes to the slave in case of "keepSlave" option enabled.
138138
if ($this->_conn !== null && ! $requestedConnectionChange) {
139-
return false;
139+
return;
140140
}
141141

142142
$forceMasterAsSlave = false;
@@ -153,7 +153,7 @@ public function connect($connectionName = null)
153153
$this->connections['slave'] = $this->_conn;
154154
}
155155

156-
return false;
156+
return;
157157
}
158158

159159
if ($connectionName === 'master') {
@@ -167,12 +167,12 @@ public function connect($connectionName = null)
167167
$this->connections['slave'] = $this->_conn = $this->connectTo($connectionName);
168168
}
169169

170-
if ($this->_eventManager->hasListeners(Events::postConnect)) {
171-
$eventArgs = new ConnectionEventArgs($this);
172-
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
170+
if (! $this->_eventManager->hasListeners(Events::postConnect)) {
171+
return;
173172
}
174173

175-
return true;
174+
$eventArgs = new ConnectionEventArgs($this);
175+
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
176176
}
177177

178178
/**

lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ public function __construct($stmt)
8989
/**
9090
* {@inheritdoc}
9191
*/
92-
public function bindValue($param, $value, $type = ParameterType::STRING)
92+
public function bindValue($param, $value, $type = ParameterType::STRING) : void
9393
{
94-
return $this->bindParam($param, $value, $type);
94+
$this->bindParam($param, $value, $type);
9595
}
9696

9797
/**
9898
* {@inheritdoc}
9999
*/
100-
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
100+
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) : void
101101
{
102102
switch ($type) {
103103
case ParameterType::INTEGER:
@@ -122,8 +122,6 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l
122122
$this->bind($column, $variable, DB2_PARAM_IN, DB2_CHAR);
123123
break;
124124
}
125-
126-
return true;
127125
}
128126

129127
/**
@@ -144,17 +142,17 @@ private function bind($position, &$variable, int $parameterType, int $dataType)
144142
/**
145143
* {@inheritdoc}
146144
*/
147-
public function closeCursor()
145+
public function closeCursor() : void
148146
{
149147
$this->bindParam = [];
150148

151-
if (! db2_free_result($this->stmt)) {
152-
return false;
149+
if (! $this->result) {
150+
return;
153151
}
154152

155-
$this->result = false;
153+
db2_free_result($this->stmt);
156154

157-
return true;
155+
$this->result = false;
158156
}
159157

160158
/**
@@ -187,7 +185,7 @@ public function errorInfo()
187185
/**
188186
* {@inheritdoc}
189187
*/
190-
public function execute($params = null)
188+
public function execute($params = null) : void
191189
{
192190
if ($params === null) {
193191
ksort($this->bindParam);
@@ -222,26 +220,24 @@ public function execute($params = null)
222220
}
223221

224222
$this->result = true;
225-
226-
return $retval;
227223
}
228224

229225
/**
230226
* {@inheritdoc}
231227
*/
232-
public function setFetchMode($fetchMode, ...$args)
228+
public function setFetchMode($fetchMode, ...$args) : void
233229
{
234230
$this->defaultFetchMode = $fetchMode;
235231

236232
if (isset($args[0])) {
237233
$this->defaultFetchClass = $args[0];
238234
}
239235

240-
if (isset($args[1])) {
241-
$this->defaultFetchClassCtorArgs = (array) $args[2];
236+
if (! isset($args[1])) {
237+
return;
242238
}
243239

244-
return true;
240+
$this->defaultFetchClassCtorArgs = (array) $args[2];
245241
}
246242

247243
/**

lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Doctrine\DBAL\Driver\Mysqli;
44

55
use Doctrine\DBAL\DBALException;
6+
use Doctrine\DBAL\Driver\DriverException;
67
use Doctrine\DBAL\Driver\Statement;
78
use Doctrine\DBAL\Driver\StatementIterator;
89
use Doctrine\DBAL\Exception\InvalidArgumentException;
@@ -101,7 +102,7 @@ public function __construct(mysqli $conn, $prepareString)
101102
/**
102103
* {@inheritdoc}
103104
*/
104-
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
105+
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) : void
105106
{
106107
assert(is_int($column));
107108

@@ -111,14 +112,12 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l
111112

112113
$this->_bindedValues[$column] =& $variable;
113114
$this->types[$column - 1] = self::$_paramTypeMap[$type];
114-
115-
return true;
116115
}
117116

118117
/**
119118
* {@inheritdoc}
120119
*/
121-
public function bindValue($param, $value, $type = ParameterType::STRING)
120+
public function bindValue($param, $value, $type = ParameterType::STRING) : void
122121
{
123122
assert(is_int($param));
124123

@@ -129,14 +128,12 @@ public function bindValue($param, $value, $type = ParameterType::STRING)
129128
$this->_values[$param] = $value;
130129
$this->_bindedValues[$param] =& $this->_values[$param];
131130
$this->types[$param - 1] = self::$_paramTypeMap[$type];
132-
133-
return true;
134131
}
135132

136133
/**
137134
* {@inheritdoc}
138135
*/
139-
public function execute($params = null)
136+
public function execute($params = null) : void
140137
{
141138
if ($params !== null && count($params) > 0) {
142139
if (! $this->bindUntypedValues($params)) {
@@ -199,12 +196,12 @@ public function execute($params = null)
199196
}
200197

201198
$this->result = true;
202-
203-
return true;
204199
}
205200

206201
/**
207202
* Binds parameters with known types previously bound to the statement
203+
*
204+
* @throws DriverException
208205
*/
209206
private function bindTypedParameters()
210207
{
@@ -408,12 +405,10 @@ public function errorInfo()
408405
/**
409406
* {@inheritdoc}
410407
*/
411-
public function closeCursor()
408+
public function closeCursor() : void
412409
{
413410
$this->_stmt->free_result();
414411
$this->result = false;
415-
416-
return true;
417412
}
418413

419414
/**
@@ -439,11 +434,9 @@ public function columnCount()
439434
/**
440435
* {@inheritdoc}
441436
*/
442-
public function setFetchMode($fetchMode, ...$args)
437+
public function setFetchMode($fetchMode, ...$args) : void
443438
{
444439
$this->_defaultFetchMode = $fetchMode;
445-
446-
return true;
447440
}
448441

449442
/**

0 commit comments

Comments
 (0)