From aafddece15cd22d974c5211de9bb6c2a1bb24181 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 3 Apr 2010 14:01:53 +0200 Subject: [PATCH] Removed code duplication. --- lib/Predis.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Predis.php b/lib/Predis.php index aada55fe..a70c91f0 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -322,24 +322,24 @@ class ResponseBulkHandler implements IResponseHandler { if ($dataLength > 0) { $value = $connection->readBytes($dataLength); - if ($connection->readBytes(2) !== ResponseReader::NEWLINE) { - Utilities\Shared::onCommunicationException(new MalformedServerResponse( - $connection, 'Did not receive a new-line at the end of a bulk response' - )); - } + self::discardNewLine($connection); return $value; } else if ($dataLength == 0) { - if ($connection->readBytes(2) !== ResponseReader::NEWLINE) { - Utilities\Shared::onCommunicationException(new MalformedServerResponse( - $connection, 'Did not receive a new-line at the end of a bulk response' - )); - } + self::discardNewLine($connection); return ''; } return null; } + + private static function discardNewLine(Connection $connection) { + if ($connection->readBytes(2) !== ResponseReader::NEWLINE) { + Utilities\Shared::onCommunicationException(new MalformedServerResponse( + $connection, 'Did not receive a new-line at the end of a bulk response' + )); + } + } } class ResponseMultiBulkHandler implements IResponseHandler {