浏览代码

Move the reducer function in Predis\Commands\Command::__toString() to a protected method.

Daniele Alessandri 14 年之前
父节点
当前提交
dac0104267
共有 1 个文件被更改,包括 13 次插入8 次删除
  1. 13 8
      lib/Predis/Commands/Command.php

+ 13 - 8
lib/Predis/Commands/Command.php

@@ -63,14 +63,19 @@ abstract class Command implements ICommand {
         return $data;
     }
 
+    protected function toStringArgumentReducer($accumulator, $argument) {
+        if (strlen($argument) > 32) {
+            $argument = substr($argument, 0, 32) . '[...]';
+        }
+        $accumulator .= " $argument";
+        return $accumulator;
+    }
+
     public function __toString() {
-        $reducer = function($acc, $arg) {
-            if (strlen($arg) > 32) {
-                $arg = substr($arg, 0, 32) . '[...]';
-            }
-            $acc .= " $arg";
-            return $acc;
-        };
-        return array_reduce($this->getArguments(), $reducer, $this->getId());
+        return array_reduce(
+            $this->getArguments(),
+            array($this, 'toStringArgumentReducer'),
+            $this->getId()
+        );
     }
 }