Skip to content

Commit 868d429

Browse files
committed
Removal of useless try / catch
1 parent 287b231 commit 868d429

File tree

2 files changed

+12
-43
lines changed

2 files changed

+12
-43
lines changed

Model/Datasource/RedisSource.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,18 @@ public function connect() {
141141
* @return bool True if connecting to the DataSource succeeds, else false
142142
*/
143143
protected function _connect() {
144-
// TODO: Remove useless try / catch?
145-
try {
146-
if ($this->config['unix_socket']) {
147-
return $this->_connection->connect($this->config['unix_socket']);
148-
} elseif (!$this->config['persistent']) {
149-
return $this->_connection->connect(
150-
$this->config['host'], $this->config['port'], $this->config['timeout']
151-
);
152-
} else {
153-
$persistentId = crc32(serialize($this->config));
154-
155-
return $this->_connection->pconnect(
156-
$this->config['host'], $this->config['port'], $this->config['timeout'], $persistentId
157-
);
158-
}
159-
} catch (RedisException $e) {
160-
return false;
144+
if ($this->config['unix_socket']) {
145+
return $this->_connection->connect($this->config['unix_socket']);
146+
} elseif (!$this->config['persistent']) {
147+
return $this->_connection->connect(
148+
$this->config['host'], $this->config['port'], $this->config['timeout']
149+
);
150+
} else {
151+
$persistentId = crc32(serialize($this->config));
152+
153+
return $this->_connection->pconnect(
154+
$this->config['host'], $this->config['port'], $this->config['timeout'], $persistentId
155+
);
161156
}
162157
}
163158

Test/Case/Model/Datasource/RedisSourceTest.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -152,32 +152,6 @@ public function testIsConnected() {
152152
$this->assertFalse($result);
153153
}
154154

155-
/**
156-
* testConnectException method
157-
*
158-
* @return void
159-
*/
160-
public function testConnectException() {
161-
// Get mock, without the constructor being called
162-
$Source = $this->getMockBuilder('TestRedisSource')->disableOriginalConstructor()->getMock();
163-
164-
$unixSocket = '/foo/bar';
165-
166-
$Source->config = array('unix_socket' => $unixSocket);
167-
$Source->_connection = $this->getMock('Redis', array('connect'));
168-
169-
// Set expectations for connect calls
170-
$Source->_connection->expects($this->once())->method('connect')
171-
->with($this->equalTo($unixSocket))->will($this->throwException(new RedisException));
172-
173-
// Now call _connect
174-
$reflectedClass = new ReflectionClass('TestRedisSource');
175-
$connect = $reflectedClass->getMethod('_connect');
176-
$result = $connect->invoke($Source);
177-
178-
$this->assertFalse($result);
179-
}
180-
181155
/**
182156
* testConnectUnixSocket method
183157
*

0 commit comments

Comments
 (0)