Skip to content

Commit

Permalink
fix code style 2
Browse files Browse the repository at this point in the history
  • Loading branch information
nike-17 committed Mar 15, 2012
1 parent 2fd8b9f commit 8b8f8e3
Showing 1 changed file with 44 additions and 22 deletions.
66 changes: 44 additions & 22 deletions library/Rediska/Connection.php
Expand Up @@ -68,7 +68,8 @@ class Rediska_Connection extends Rediska_Options {
* @return boolean
* @uses self::getStreamContext()
*/
public function connect() {
public function connect()
{
if (!$this->isConnected()) {
$socketAddress = 'tcp://' . $this->getHost() . ':' . $this->getPort();

Expand Down Expand Up @@ -147,7 +148,8 @@ public function connect() {
*
* @return boolean
*/
public function disconnect() {
public function disconnect()
{
if ($this->isConnected()) {
@fclose($this->_socket);

Expand All @@ -162,7 +164,8 @@ public function disconnect() {
*
* @return boolean
*/
public function isConnected() {
public function isConnected()
{
return is_resource($this->_socket);
}

Expand All @@ -172,7 +175,8 @@ public function isConnected() {
* @param $string
* @return boolean
*/
public function write($string) {
public function write($string)
{
if ($string !== '') {
$needToWrite = (string) $string . Rediska::EOL;

Expand Down Expand Up @@ -210,7 +214,8 @@ public function write($string) {
* @param integer $length
* @return boolean
*/
public function read($length) {
public function read($length)
{
if (!$this->isConnected()) {
throw new Rediska_Connection_Exception("Can't read without connection to Redis server. Do connect or write first.");
}
Expand All @@ -235,7 +240,8 @@ public function read($length) {
* @throws Rediska_Connection_TimeoutException
* @return string
*/
public function readLine() {
public function readLine()
{
if (!$this->isConnected()) {
throw new Rediska_Connection_Exception("Can't read without connection to Redis server. Do connect or write first.");
}
Expand Down Expand Up @@ -272,7 +278,8 @@ public function readLine() {
* @param $timeout
* @return Rediska_Connection
*/
public function setReadTimeout($timeout) {
public function setReadTimeout($timeout)
{
$this->_options['readTimeout'] = $timeout;

if ($this->isConnected()) {
Expand All @@ -291,7 +298,8 @@ public function setReadTimeout($timeout) {
* @param $flag
* @return Rediska_Connection
*/
public function setBlockingMode($flag = true) {
public function setBlockingMode($flag = true)
{
$this->_options['blockingMode'] = $flag;

if ($this->isConnected()) {
Expand All @@ -306,7 +314,8 @@ public function setBlockingMode($flag = true) {
*
* @return string
*/
public function getHost() {
public function getHost()
{
return $this->_options['host'];
}

Expand All @@ -315,7 +324,8 @@ public function getHost() {
*
* @return string
*/
public function getPort() {
public function getPort()
{
return $this->_options['port'];
}

Expand All @@ -324,7 +334,8 @@ public function getPort() {
*
* @return string
*/
public function getWeight() {
public function getWeight()
{
return $this->_options['weight'];
}

Expand All @@ -333,7 +344,8 @@ public function getWeight() {
*
* @return string
*/
public function getPassword() {
public function getPassword()
{
return $this->_options['password'];
}

Expand All @@ -342,7 +354,8 @@ public function getPassword() {
*
* @return string
*/
public function getTimeout() {
public function getTimeout()
{
if (null !== $this->_options['timeout']) {
return $this->_options['timeout'];
} else {
Expand All @@ -355,7 +368,8 @@ public function getTimeout() {
*
* @return string
*/
public function getAlias() {
public function getAlias()
{
if ($this->_options['alias'] != '') {
return $this->_options['alias'];
} else {
Expand All @@ -372,7 +386,8 @@ public function getAlias() {
* @return mixed null or resource
* @see self::connect()
*/
public function getStreamContext() {
public function getStreamContext()
{
if ($this->_options['streamContext'] !== null) {
if (is_resource($this->_options['streamContext'])) {
return $this->_options['streamContext'];
Expand All @@ -390,7 +405,8 @@ public function getStreamContext() {
* @param $length Lenght of bytes to read
* @return string
*/
protected function _readAndThrowException($length) {
protected function _readAndThrowException($length)
{
$data = @stream_get_contents($this->_socket, $length);

$info = stream_get_meta_data($this->_socket);
Expand All @@ -411,7 +427,8 @@ protected function _readAndThrowException($length) {
*
* @return string
*/
public function __invoke($command) {
public function __invoke($command)
{
$exec = new Rediska_Connection_Exec($this, $command);

return $exec->execute();
Expand All @@ -420,14 +437,16 @@ public function __invoke($command) {
/**
* Return alias to strings
*/
public function __toString() {
public function __toString()
{
return $this->getAlias();
}

/**
* Disconnect on destrcuct connection object
*/
public function __destruct() {
public function __destruct()
{
if (!$this->_options['persistent']) {
$this->disconnect();
}
Expand All @@ -436,22 +455,25 @@ public function __destruct() {
/**
* Do not clone socket
*/
public function __clone() {
public function __clone()
{
$this->_socket = null;
}

/**
* Return attempts count
* @return integer
*/
protected function _getAttemptsCount() {
protected function _getAttemptsCount()
{
return $this->_attemptsCount;
}

/**
* Increment attempts count
*/
protected function _checkAttemptsCount() {
protected function _checkAttemptsCount()
{
$maxReconnectAttempts = $this->getOption('maxReconnectAttempts');
if ($maxReconnectAttempts && $this->_attemptsCount < $maxReconnectAttempts) {
$this->_attemptsCount++;
Expand Down

0 comments on commit 8b8f8e3

Please sign in to comment.