Sfoglia il codice sorgente

Removed code duplication.

Daniele Alessandri 15 anni fa
parent
commit
aafddece15
1 ha cambiato i file con 10 aggiunte e 10 eliminazioni
  1. 10 10
      lib/Predis.php

+ 10 - 10
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 {